PDA

View Full Version : Blending Color with Texture?



jalway
03-30-2006, 07:42 PM
Hello,

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!
...John

ZbuffeR
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);

jalway
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.



glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, texIdx);
glColor4fv(color);
glBegin(GL_QUADS)
glTexCoord2f(0.0f,0.0f);
glVertex3fv(x1,y1,z1);
glTexCoord2f(1.0f,0.0f);
glVertex3fv(x2,y2,z2);
glTexCoord2f(1.0f,0.0f);
glVertex3fv(x3,y3,z3);
glTexCoord2f(1.0f,0.0f);
glVertex3fv(x4,y4,z4);
glEnd(GL_QUADS);

Ehsan Kamrani
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?
-Ehsan-

Komat
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.

jalway
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.

...John

jalway
03-31-2006, 06:51 PM
Komat,
You nailed it! Exactly right.

I turned lighting off, and it worked. I probably should have known that.

Thanks much.