coloring textures (OpenGL)

Started by
4 comments, last by woodruff 16 years, 2 months ago
Hi! I have a textured quad that I want to colorize, lets say: red. Easy task, I thought... ;) But if I use glColor4ub(255, 0, 0, 255) the "bright" colors of the texture get red but the "dark" ones stay (ie: black always stays black) I think thats because the colors get multiplied, but I don't want black to stay black I want it to turn into a darker red. How can I change this? I tried to use different glBlendFunc parameters, but that just influences how the texture is drawn on the background(-texture) One solution would be to render the same texture (changed to red in a photoshop) with 50% alpha on top of the texture, but I want to avoid that because I use various frames within the texture. Is there a elegant way of tinting the texture red? Thanks in advance!
Advertisement
Easy task.
Use Gray-color (white to black) texture = set any color.
// or use shader ...
Thanks for your reply, but thats not possible - the texture contains various colors, which should all "fade" to red... (including black)
You'll want to look at the glTexEnv function with the GL_TEXTURE_ENV_MODE parameter (IIRC; I use shaders so I don't actually use it myself). I'm not positive if there's one that will do exactly what you want but the possible values are listed in the docs for glTexEnv.
The easiest way to do that is to use glPixelTransfer. If you set glPixelTransferf(GL_RED_BIAS, 0.2) before creating texture, your textures' red component will be shifted by 0.2, so black pixels will became lighter.
I tried out glPixelTransfer and glTexEnv but the results were nonsatisfying.

The only solution would be to load a the same texture again and set glPixelTransfer. So I could render the second (colored) texture above the first one and adust the "coloreness" with alpha blending...

Funny that such a simple task requires a workaround... :)

Thanks for all replys, anyway!

This topic is closed to new replies.

Advertisement