View Full Version : Blending Color with Texture?
03-30-2006, 07:42 PM
I'm attempting to blend a color with a texture for a particle system, but am not sure how this is done.
What I want to do is be able to change the color of the particle by changing glColor3fv() when outputting a quad between glBegin(GL_QUADS) and glEnd(). The particle is textured, so it would be a blend of that color with the texture.
Is there an easy way to do this?
I'm using OpenGL 1.2.
Thanks for any help!
03-31-2006, 02:22 AM
It is the default to modulate color with texture.
The explicit call is :
glTexEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
03-31-2006, 04:21 PM
Thanks for your response.
That's what I'd thought, but for some reason I can't get it to work.
Looking at my Red Book, page 403, table 9-4, for a GL_RGBA format the following formula should work C=Cf*Ct and A=Af*At, where f is the incoming fragment ( I assumed this is designated by glColor4fv(color) ), and t is the texture.
Here is a stripped down version of my code. I've been playing with this for a long time, and just can't get it to work. The texture displays right, but for some reason whenever I change the color value it has no effect. If I eliminate texturing, then the quad displays color as it should, but as soon as I place texturing in there, the texturing supercedes the color, and I see no color tint come through.
I even have the Nat Robins tutorial example, but mine won't cooperate. Very confusing.
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
03-31-2006, 06:02 PM
glEnd( GL_QUADS ) ? As i know, glEnd() doesn't get any parameters.
GL_MODULATE should work. However try to enable blending and use the function glBlendFunc() and see the results. Does it work?
03-31-2006, 06:39 PM
Originally posted by jalway:
If I eliminate texturing, then the quad displays color as it should, but as soon as I place texturing in there, the texturing supercedes the color, and I see no color tint come through.
What OGL commands are different in the version that applies texturing and the version that does not?
Do you have lighting enabled in the version with texturing? If lighting is enabled without corresponding setup of glColorMaterial(), color set by glColor4fv is ignored.
03-31-2006, 06:46 PM
Thanks for the response, Ehsan.
The glEnd()is a typo on my part.
I have tried using the blending function for this without success, but I don't think that should be required. I believe that's for the GL_TEXTURE_ENV_COLOR paramater in pname, as per the Red Book. I could be wrong, of course.
I have found, btw, that if I change the material's color, that is modulated with the texture, and gives me the functionality I was seeking, but the other should work too.
03-31-2006, 06:51 PM
You nailed it! Exactly right.
I turned lighting off, and it worked. I probably should have known that.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.