Raf CG
Raf CG
Dept of CSE 2
OpenGL Bitmap Function
The OpenGL bitmap function, glBitmap, is a 2D graphics function that renders a bitmap image
at a specified location on the screen.
It's a fundamental tool for displaying 2D graphics, such as: Icons, Sprites, Textures, Fonts,
Graphs, Charts.
Renders uncompressed bitmap images
Works in screen space, ignoring 3D transformations
Supports various image formats (e.g., BMP, PNG, JPEG)
Efficient for 2D graphics rendering
Benefits:
Easy to use
Fast rendering
Suitable for various 2D graphics applications
Dept of CSE 3
How to use :
A binary array pattern is defined with the function:
glBitmap (width, height, x0, y0, xOffset, yOffset, bitShape);
glBitmap is a function that draws a bitmap image on the screen.
width and height: size of the pattern (number of columns and rows)
x0 and y0: the starting point of the pattern (can be positive or negative)
bitShape: a grid of 1s and 0s that defines the pattern
- 1 means display a pixel in a previously chosen color
- 0 means leave the pixel alone
xOffset and yOffset: how much to move the starting point after displaying the pattern
The pattern is placed at a specific location on the screen, called the current raster position.
The starting point (x0, y0) of the pattern aligns with this location. After displaying the pattern,
the location moves by the amount specified by xOffset and yOffset, ready for the next pattern.
Dept of CSE 4
We use the following routine to set the coordinates for the current raster position:
glRasterPos* ( )
The glRasterPos function sets the current raster position, which is where the next bitmap will
be placed. This function uses the same codes as the glVertex function to specify the
coordinates.
Think of it like setting the location of a stamp pad on a piece of paper. You can specify the
coordinates in world coordinates (like a map), and the computer will translate them to screen
coordinates (like the actual position on the paper).
For 2D examples, you can simply use integer coordinates (like 100, 200) to specify the
position directly on the screen. If you don't set the position, it defaults to the origin (0, 0, 0),
like the starting point of a grid.
When you set the position for a bitmap using glRasterPos, the color that is currently selected
will be used for that bitmap. If you change the color afterwards, it won't affect the bitmap that
you just placed - it will stay the same color that was selected when you placed it.
Dept of CSE 5
• When storing a rectangular bitmap, each row is stored in groups of 8 bits (like a set of 8 light
switches). But when creating the bitmap, you can use any grid size you want, like a 10x9 grid.
• For example, Figure 27 shows a bit pattern defined on a 10-row by 9-column grid, where the binary
data is specified with 16 bits for each row.
• If your picture has more bits than the storage format can handle (like extra columns beyond the 9th
column), those extra bits just get ignored when the picture is displayed.
• We apply the bit pattern of Figure 27 to a frame-buffer location with the following code section:
GLubyte bitShape [20] = { 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0xff,
0x80, 0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x08, 0x00}; //defines the bitmap pattern as a series of
numbers (0x1c, 0x00, etc.) that represent the rows of the bitmap.
glPixelStorei (GL_UNPACK_ALIGNMENT, 1); // sets the storage mode for pixels to unpack the
bitmap correctly..
glRasterPos2i (30, 40); //sets the position on the screen where the bitmap will be placed (at
coordinates (30, 40)).
glBitmap (9, 10, 0.0, 0.0, 20.0, 15.0, bitShape);// applies the bitmap pattern to the screen using the
glBitmap function, specifying the size of the bitmap (9 columns, 10 rows), the position (0.0, 0.0), a
coordinate offset with the values (20.0, 15.0),and the bitmap data itself (bitShape).
Dept of CSE 6
Dept of CSE 7
Dept of CSE 8