Log in

View Full Version : OpenGL question


Mike Wiering
07-08-2004, 07:30 PM
Could anyone tell me, is there an easy way to draw a sprite (texture) and add a color to it, making it lighter, but not transparent?

What I do now works fine, but I think it should be possible to do this without having to draw the sprite twice:


glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f (1.0, 1.0, 1.0, 1.0);

... draw the sprite ...

glBlendFunc (GL_SRC_ALPHA, GL_ONE);
glColor4f (AddR, AddG, AddB, AddA);

... draw the sprite again ...

WreckerOne
07-08-2004, 09:43 PM
Use the register combiner extension or constant blend color extension.

Its not clear whether you want to modify the alpha value used to blend, or the actual color of the texture being blended.

Jim Buck
07-08-2004, 10:09 PM
This would only work depending on the colors in your bitmap, but create your bitmap in such a way so that glColor3f(.5, .5, .5) would give you the "normal" version of your sprite so that higher-than-.5 values would give you the brighter version. (If you don't need to be twice as bright, you could make it so that .7 or some other value is your "normal" sprite.)

Mike Wiering
07-10-2004, 01:45 AM
Thanks for your replies. What I would to be able to do is modify the color that is added. I just thought OpenGL would have a simple way to do that in one pass, since it is very easy to make sprites darker.

I can't make the images look normal at (0.5,0.5,0.5), because then gray would be the brightest color I could use. I'll see if I can find info on those extesions.

Jim Buck
07-10-2004, 08:39 AM
Yeah, that was the unfortunate limitation of my off-the-cuff idea. It's lame that OpenGL clamps the colors to [0, 1]. Even packages like Maya output vertex colors that can be greater than 1.