Search code examples
opengltexture-mapping

Drawing a polygon with color in OpenGL causes texture colors to change


I'm working on a simulation program that draws points and other primitives on top of a large 2D rectangle with a texture mapped onto it.

The problem is, when I draw a polygon and specify a color for the vertices using glColor3f, that color appears to effect the colors of the texture and not just the polygon that I drew. So drawing a red polygon appears to "bleed" onto the entire texture and everything appears reddish.

I attempted to fix this by using glDisable(GL_TEXTURE_2D) prior to drawing the polygon and then enabling again. But this doesn't seem to have any effect.


Solution

  • glColor3f changes the color of everything you draw after it's called, as you're setting OpenGL's color state. This is just how OpenGL works in general. (glTranslate/Rotate/Scalef, glMultMatrix, glLoadIdentity, etc. work in the same way as they change the transformation state using the matrix chosen by the matrix mode state (set with glMatrixMode))

    In order to "reset" the color back to the default, call glColor3f(1.0f, 1.0f, 1.0f);