Coloring a bitmap: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
Ehsan (talk | contribs)
No edit summary
 
Kwi (talk | contribs)
Reformatted, adding note on disabling lighting calculations.
Line 1: Line 1:
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:
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:
<pre>
glColor3f( 1.0f, 0.0f, 0.0f );
glColor3f( 1.0f, 0.0f, 0.0f );


Line 20: Line 23:


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

Revision as of 17:13, 23 September 2009

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);.