Difference between revisions of "Coloring a bitmap"

From OpenGL Wiki
Jump to: navigation, search
(Reformatted, adding note on disabling lighting calculations.)
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>.

Revision as of 21:45, 13 February 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);.