How do I "reset" the color in OpenGl ES 1.0/1.1?

| | August 6, 2015

In my 2D game I use glColor4f() to set the color and draw my screen border rectangles
but when I try to start drawing my game objects, made up of a texture
on a rectangular “quad”, using GL10.GL_TEXTURE_2D, GL10.GL_VERTEX_ARRAY
and GL10.GL_TEXTURE_COORD_ARRAY no GL10.GL_COLOR_ARRAY, it uses the “current
color” from glColor4f().

My question is what do I need to set/reset in OpenGl ES to re-enable it to
use the colors from the texture when I try to draw them? If I comment out the border drawing, so glColor4f() never gets called, the colors are fine.

I’m not using double buffering. I read that once you set the color with
glColor4f() it stays set, unless you possibly use glPushAttrib(GL_CURRENT_BIT),
but I heard that that’s expensive, time wise.

3 Responses to “How do I "reset" the color in OpenGl ES 1.0/1.1?”

  1. Quoting the author:


    I got it working:

    The textures are made up of several colors. I went ahead and changed it to use a color array, and not use glColor4f(), when drawing the solid color borders, adding them with glColorPointer() and in beginDrawing() it does glEnableClientState() or glDisableClientState() with GL10.GL_COLOR_ARRAY and it’s working pretty well.

  2. Sean Middleditch on November 30, -0001 @ 12:00 AM

    Full explanation:

    OpenGL’s (and GLES’) default behavior is to modulate the currently set color with the texture with a simple multiplication. That is, it multiplies the color with the value at the texture.

    The default color is white. White is defined as <1.0f, 1.0f, 1.0f, 1.0f>. One times anything is itself, so modulating white with the texture color results in the texture color itself.

    If you were to change the color to red (<1.0f, 0.0f, 0.0f, 1.0f>) then the result would be red times the texture color; since zero times anything is zero, the result would be <1.0f * Texture.Red, 0.0f * Texture.Green, 0.0f * Texture.Blue, 1.0f * Texture.Alpha> = <Texture.Red, 0.0f, 0.0f, Texture.Alpha>. In other words, you’d see just the red component of the texture color at the texture’s opacity.

    That’s useful behavior to have for some effects, especially back before more complicated masking and blending operations became available or the advent of shaders. The effect doesn’t necessarily look all that good, but it works. (The problem is that you’d lose all the countours of green and blue objects, so what you probably want is a color modulation of luminocity values computed from all three color channels.)

    You can’t get too much control without switching to GLES 2+ and using shaders.

    The result of all this math on your situation is what’s already been suggested: reset GL’s current color to white before drawing in order to see textured objects ‘properly’.

  3. You should set the color to white glColor4f(1,1,1,1) before drawing textured geometry.

Leave a Reply