opengl es color question

frozen
Unregistered
 
Post: #1
Hi!

I have 2d objects with vertices contain xy, uv, rgba. I'm rendering them onto the screen as gui elements. Now when they are fading out, I modify rgba values in all vertices in each frame.

Is there a better way to modify the color? Is there some kind of _current color_ with that the opengl es multiplies each color component containted by the vertices being rendered?


Thanks in advance,
frozen
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #2
Not sure I totally understand, but yes, the single environment color is glColor4f(r, g, b, a); You don't have to set the color of the vertices themselves. You just set the color state once, and it stays that color until you change it.
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #3
Make sure you've done

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

in your init somewhere first though or glColor4f won't have any effect on textures.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #4
I thought GL_MODULATE was default. Looks like I have that in my init(s) too, so maybe not. Sneaky (certainly can't hurt to add it regardless though)
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #5
AnotherJake Wrote:I thought GL_MODULATE was default. Looks like I have that in my init(s) too, so maybe not. Sneaky (certainly can't hurt to add it regardless though)

I always thought it was too until I did my first iPhone game and glColor4f stopped working. Generally best to set it anyway in case it's not always set by default.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #6
I'm pretty sure the default is modulate - but you need to glEnable(GL_COLOR_MATERIAL) to get colour modulation working.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
MODULATE is the default. It won't change unless your code changes it. COLOR_MATERIAL only matters if you have lighting enabled.

For completeness: there are at least three ways to "fade out" (that is, modulate two colors) in OpenGL ES with the capabilities the iPhone gives you:

1) multiply the texture color with the primary vertex color. This is what the default MODULATE TexEnv does. The primary vertex color comes from the ColorPointer, if COLOR_ARRAY is enabled, else it comes from the current vertex, which you can set with Color4f as said above.

This is the easiest way, and probably best for simply fading out a couple of quads.

2) multiply the texture color with the TexEnv CONSTANT color. You need to set up COMBINE sources and the constant color with TexEnv. This has the advantage that color data does not need to be sent per vertex, so will be slightly faster, but this won't be noticeable for only a few quads. The downside is that the constant color is stored in limited precision on the iPhone, so a smooth fade out won't be as smooth as you'd get with the primary color. You also can't change the color per vertex, so no gradient fades.

3) multiply the texture color with another texture. Set up TexEnv sources however you like to mix the texture rgb and alpha channels. This is more flexible, so you can fade with masks, but is definitely more expensive since you need to sample two textures per pixel.
Quote this message in a reply
Post Reply