Jump to content


Blending Color with Texture in OpenGL?


5 replies to this topic

#1 Thales

    Member

  • Members
  • PipPip
  • 32 posts

Posted 31 March 2006 - 03:06 AM

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!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 31 March 2006 - 05:21 AM

The texture will automatically be multiplied by the color in the default OpenGL state. So just set your color along with your texture and it will work.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Thales

    Member

  • Members
  • PipPip
  • 32 posts

Posted 31 March 2006 - 10:26 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();



#4 Thales

    Member

  • Members
  • PipPip
  • 32 posts

Posted 01 April 2006 - 12:53 AM

Okay, I found the problem. I had lighting enabled.

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 01 April 2006 - 12:55 AM

Yes, in that case the material properties supersede the color. But if you glEnable(GL_COLOR_MATERIAL) then setting the color will work again (and you can have lighting).
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 Thales

    Member

  • Members
  • PipPip
  • 32 posts

Posted 01 April 2006 - 01:02 AM

Thanks, Reedbeta, that worked well!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users