Coloring a bitmap: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
Kwi (talk | contribs)
Reformatted, adding note on disabling lighting calculations.
Zyx 2000 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
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:
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>
<source lang="c">
glColor3f( 1.0f, 0.0f, 0.0f );
glColor3f(1.0f, 0.0f, 0.0f);
 
glBegin(GL_POLYGON);
glBegin( GL_POLYGON );
 
...
...
glEnd();
glEnd();
 
glRasterPos2i(xr, yr);
glRasterPos2i( xr, yr );
glColor3f(0.0f, 1.0f, 0.0f);
 
glBitmap(64, 64, 0.0, 0.0, 0.0, 0.0, check);
glColor3f( 0.0f, 1.0f, 0.0f );
glBegin(GL_POLYGON);
 
glBitmap( 64, 64, 0.0, 0.0, 0.0, 0.0, check );
 
glBegin( GL_POLYGON );
 
...
...
glEnd();
glEnd();
</pre>
</source>


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

Latest revision as of 19:02, 9 July 2011

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