Contents / Previous / Next


Bitmaps and Fonts

A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.

In the Figure note that the visible part of the F character is at most 10 bits wide. Bitmap data is always stored in chunks that are multiples of 8 bits, but the width of the actual bitmap doesn't have to be a multiple of 8. The bits making up a bitmap are drawn starting from the lower left corner: First, the bottom row is drawn, then the next row above it, and so on. As you can tell from the code, the bitmap is stored in memory in this order - the array of rasters begins with 0xc0, 0x00, 0xc0, 0x00 for the bottom two rows of the F and continues to 0xff, 0xc0, 0xff, 0xc0 for the top two rows.

The commands glRasterPos*() and glBitmap() position and draw a single bitmap on the screen. glPixelStorei() describes how the bitmap data is stored in computer memory.

Example (C code):

  // Bitmap for the letter F.
  private byte rasterF[] = 
  { 
    (byte) 0xc0, (byte) 0x00, (byte) 0xc0, (byte) 0x00, (byte) 0xc0,
    (byte) 0x00, (byte) 0xc0, (byte) 0x00, (byte) 0xc0, (byte) 0x00,
    (byte) 0xff, (byte) 0x00, (byte) 0xff, (byte) 0x00, (byte) 0xc0,
    (byte) 0x00, (byte) 0xc0, (byte) 0x00, (byte) 0xc0, (byte) 0x00,
    (byte) 0xff, (byte) 0xc0, (byte) 0xff, (byte) 0xc0 
  };

  // The glBitmap function is the current jogl version (1.1.1)
  // requires a byte buffer not an array.
  ByteBuffer bufF;

  public void init( GL gl ) 
    {
      // Init byte buffer with just the letter F.
      bufF = ByteBuffer.allocateDirect( rasterF.length );
      bufF.put( rasterF );
      bufF.rewind();
    }

  private void drawF(GL gl) 
    {
      gl.glColor3f( 1f, 1f, 1f );
      gl.glWindowPos2i(160, 160);
      gl.glBitmap(10, 12, 0.0f, 0.0f, 12.0f, 0.0f, bufF );
    }