This is G o o g l e's cache of http://ironbark.bendigo.latrobe.edu.au/~fran/int32gp/wk05/tt08.html.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:jduSmyX48C4J:ironbark.bendigo.latrobe.edu.au/~fran/int32gp/wk05/tt08.html+fran+soddell+%2B+tutorial+%2308&hl=en&ie=UTF-8


Google is not affiliated with the authors of this page nor responsible for its content.
These search terms have been highlighted: fran soddell tutorial 08 

Tutorial #08 INT32GP

INT32GP Graphics Programming: Tutorial #08
Bitmaps

B1.11 3:00pm Tue 20 Aug 02
B1.11 12midday Wed 21 Aug 02
You may wish to use this tutorial session to complete Assignment 1.

Advanced

This tutorial is aimed at students who wish to understand more about bitmaps through writing code to render them in OpenGL.

See Chapter 8 of the OpenGL Programming Guide V 1.1 for an in depth discussion of this tutorial.
See Lecture #07 for more information on bitmaps (and for bitmap data for a square face).
See Angel "OpenGL: A Primer" Chapter 7 for more examples, and information about reading and writing pixels.
Bitmaps can be used to display raster text. They are also used for cursors and crosshairs, and for artistic effect.
First design your bitmap. Then define a corresponding array of hexadecimal values.
   GLubyte F[24] = {
      0xc0, 0x00,
      0xc0, 0x00,
      0xc0, 0x00,
      0xc0, 0x00,
      0xc0, 0x00,
      0xff, 0x00,
      0xff, 0x00,
      0xc0, 0x00,
      0xc0, 0x00,
      0xc0, 0x00,
      0xff, 0xc0,
      0xff, 0xc0
   };
Note: the bitmap is defined in the array upside down. Each line in the bitmap is defined from left to right but the bottom line is the top of the array.

Here is a program to display this bitmap 3 times.
/*
** File:          bitmap1.c
** Description:   Renders a bitmap of letter F.
** Rev:           1.0
** Created:       12 August 2001
** Last Update:   19 August 2002
** Author:        Fran Soddell
** Email:         F.Soddell@bendigo.latrobe.edu.au
**/
#include 
/*
** window management
*/
int width=300;
int height=300;
int xPosition=50;
int yPosition=70;
/*
** colour management
*/
#define NUM_COLOURS 8
#define ALPHA 0.0
enum {red,green,blue,
      yellow,magenta,cyan,
      white,black};
typedef GLfloat colourType[3];
colourType colour[NUM_COLOURS]={
   {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},
   {1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0},
   {1.0,1.0,1.0},{0.0,0.0,0.0}
 };
/*
** define bitmap for F
*/
GLubyte F[24] = {
   0xc0, 0x00,
   0xc0, 0x00,
   0xc0, 0x00,
   0xc0, 0x00,
   0xc0, 0x00,
   0xff, 0x00,
   0xff, 0x00,
   0xc0, 0x00,
   0xc0, 0x00,
   0xc0, 0x00,
   0xff, 0xc0,
   0xff, 0xc0
};
/*
** ********************************************
*/
void renderFs(){
   int i;
   glColor3fv(colour[black]);
   glRasterPos2i (0, 0);
   for(i=0;i<3;i++)
      glBitmap (10, 12, 0.0, 0.0, 11, 0.0, F);
}
void display(void){
   glClear(GL_COLOR_BUFFER_BIT);
   renderFs();
   glFlush();
}
void reshape(int w, int h){
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y){
   switch (key) {
      case 27:
         exit(0);
   }
}
void setUpGLUT(int argc,char ** argv){
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize(width,height);
   glutInitWindowPosition(xPosition,yPosition);
   if(argc>1)
      glutCreateWindow(argv[1]);
   else
      glutCreateWindow(argv[0]);
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutDisplayFunc(display);
}
void initialiseGL(){
   glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
   glClearColor (1.0, 1.0, 1.0, 0.0);
}
int main(int argc, char ** argv){
   setUpGLUT(argc,argv);
   initialiseGL();
   glutMainLoop();
   return 0;
}

OpenGL Bitmap Functions
void glBitmap(GLsizei mapWidth,GLsizei mapHeight,
              GLfloat xOrigin,GLfloat yOrigin,
              GLfloat xMove,GLfloat yMove,
              const GLubyte *bitmap);
mapWidth mapHeight: the width and height of the pixel map in pixels
xOrigin    yOrigin: the location of the origin in the bitmap image
xMove      yMove    : the x and y offsets to be added to the current raster position after the bitmap is drawn
* bitmap               : the address of the bitmap image
void glRasterPos[234][sifd](TYPE x,TYPE y,TYPE z,TYPE w);
Specify x,y,z,w object coordinates for the raster position. For example -
glRasterPos2i (0, 0);
Specifies 2D (x,y) integer coordinates.
glPixelStore[if] (GLenum pname, TYPE param);
Sets pixel storage modes. GL_UNPACK_ALIGNMENT controls how data is unpacked from memory. See OpenGL Programming Guide for more information.
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
  1. Design a bitmap for another letter and implement it.
  2. Design a bitmap (eg. smiley face) of your own and implement it. Notice how background colour show through the parts of the bitmap that are not turned on.
  3. Explore the bitmap fonts supplied by GLUT.
Fran Soddell email:F.Soddell@bendigo.latrobe.edu.au
last updated 20 August 2002