Sign in to follow this  
phyxle

Coloring a texture

Recommended Posts

I have a texture with alpha channel and I blend it with the backgrund correctly using: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) Now I want to change the color of my textue to Red in the following way. The color of every pixel with non-zero alpha, should be changed to my desired color and the rest of the texture should remain transparent. I tried changing the blending to: glBlendFunc(GL_DST_COLOR, GL_ZERO); but the background changes to black and I loose the transparancy. Can anyone tell me gow I can blend properly without loosing the tranparancy?
glEnable(GL_BLEND);    
glEnable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    
glBindTexture(GL_TEXTURE_2D, texture); // Select Our Texture
  // Draw a quad with our object's texture on it
glBegin(GL_QUADS);                
              ...
glEnd();
			
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_DST_COLOR, GL_ZERO);  
glColor4f(1.0f, 0.0f, 0.0f, 0.0);  //mask color
	
// Draw a quad to color the texture
glBegin(GL_QUADS);                             
              ...
glEnd();



Share this post


Link to post
Share on other sites

glEnable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glBindTexture(GL_TEXTURE_2D, texture); // Select Our Texture
// Draw a quad with our object's texture on it
glBegin(GL_QUADS);
...
glEnd();



This looks fine, just change the values for RGB in the glColor statement to select the color you want.

Share this post


Link to post
Share on other sites
Define "doesn't work".

You change the color in glColor for example, red would be
glColor(1.0, 0.0, 0.0, 1.0)

and of course, glTexEnv should be GL_MODULATE so that
color alpha(always 1.0) * texture alpha = texture alpha

Share this post


Link to post
Share on other sites
Thanks V-man, FlyingSolo.
Since GL_MODULATE multiplies the texture color by the primitive color; if my texture color is black it is not going to have any effect. But I guess I have to play with GL_COMBINE options to get it right.
BTW, I am programming with visual studio 2005 and when I tried to use GL_COMBINE it did not recognize it. I checked and the version of my gl.h and it is 1.1. How can I upgrade it? should I use glew?

Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this