Coloring a bitmap

From OpenGL.org
Jump to: navigation, search

In the preceding code, we set the raster color in the same manner that we set the color in our geometric programs, and here is affected the color of the bitmap.

OpenGL stores both a present drawing color and a present raster color as part of its state. Both colors are set by glColor*(). However the present raster color is locked by the use glRasterPos*(). Thus, in the following code, the first polygon is drawn in red and the second in green. But the checkerboard is drawn in red because the raster color is the color that was in effect the last time the function glRasterPos2i() was executed:

glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
...
glEnd();
glRasterPos2i(xr, yr);
glColor3f(0.0f, 1.0f, 0.0f);
glBitmap(64, 64, 0.0, 0.0, 0.0, 0.0, check);
glBegin(GL_POLYGON);
...
glEnd();

Note: For proper color, you will probably need to disable lighting calculations while drawing bitmaps, using glDisable(GL_LIGHTING);.