opengl es color question - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: opengl es color question (/thread-2017.html)
opengl es color question - frozen - Dec 20, 2008 03:57 AM
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,
opengl es color question - AnotherJake - Dec 20, 2008 09:20 AM
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.
opengl es color question - Zwilnik - Dec 20, 2008 01:52 PM
Make sure you've done
in your init somewhere first though or glColor4f won't have any effect on textures.
opengl es color question - AnotherJake - Dec 20, 2008 02:17 PM
I thought GL_MODULATE was default. Looks like I have that in my init(s) too, so maybe not. (certainly can't hurt to add it regardless though)
opengl es color question - Zwilnik - Dec 20, 2008 02:23 PM
AnotherJake Wrote:I thought GL_MODULATE was default. Looks like I have that in my init(s) too, so maybe not. (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.
opengl es color question - Frank C. - Dec 20, 2008 04:06 PM
I'm pretty sure the default is modulate - but you need to glEnable(GL_COLOR_MATERIAL) to get colour modulation working.
opengl es color question - arekkusu - Dec 20, 2008 04:09 PM
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.