Coloring a bitmap: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
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. | 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: | |||
<source lang="c"> | |||
glColor3f(1.0f, 0.0f, 0.0f); | |||
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(); | |||
</source> | |||
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);.