changing color of textured quad (solved)

Started by
2 comments, last by Ademan555 18 years, 11 months ago
I have a black and white texture and I want to change the color of the white parts based on user settings so that I don't have to have multiple textures of the same thing only in different colors. With SDL I was doing this by modifying the palette. While I am moving to OpenGL (quite the newbie) I thought this could be done by specifying a color to blend it with but this causes the texture to be blended with everything else behind it. Any ideas what I am doing wrong or how I can prevent this? Some helpful info: using glOrtho almost exclusively (2d app) texure is loaded as a 32bpp texture (used to be 8bpp palettized in SDL) black parts of texture are fully transparent (alpha value of 0) blending and alpha test are active but have tried disabling/enabling them and all combinations of the sort. Thanks in advance [edit] SOLVED [/edit] Thanks to ProPuke I went over what I was doing and realized that I indeed needed to disable blending but I kept the alpha test in order to allow the black background (with an alpha value of 0) of the texture to be transparent. I had in error forgot to set the alpha value of the black back to 0 when I was trying to get it to work last night and doing what I could to find the cause of the problem. Thanks agan [Edited by - evillive2 on May 22, 2005 6:56:47 PM]
Evillive2
Advertisement
You were kinda on the right track..
blending is for merging with objects that are already drawn based on object colour & alpha
So, disable blending & alpha testing if you're not using it, & just change the colour direct instead

No extra functions like blending are required, everything drawn is multiplied by the vertex colours anyway

gud luck with your code ;]
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
Thanks for the quick reply ProPuke but what do you mean by "change the color direct"? Do you mean change the pixels on the texture directly before they are mapped to the quad? If this is the case then I would have to make a call to glTexImage2d to push the changes back into video memory for mapping to the quad right? I was trying to avoid doing that but if it is the only solution then I guess it is what I am in for.

Thanks again.
Evillive2
He means with glColor**() since ill assume you just want one color for the whole quad, your code would look something like this:

glColor3f(1.0f, 0.0f, 0.0f);//red
DrawQuad();

you do NOT need to put glColor**() calls inside glBegin() glEnd() blocks, you can modify the "current color" with this. the current color will be applied to each vertex untill it is changed (or there may be a state variable to not use the current color, though glColor3f(1.0f, 1.0f, 1.0f) would have the same effect anyways). Now, this should work fine for you because you're using black and white, and to the best of my knowledge each color is component wise multiplied by the current color in this way:

OutColor = CurrentColor * TexelColor; //where * is a component wise multiplication

for a black texel (texture element, or pixel in a texture)
which is something like this:

OutColor.r = CurrentColor.r * TexelColor.r;
//0.0f = CurrentColor.r * 0.0f;

OutColor.g = CurrentColor.g * TexelColor.g;
//0.0f = CurrentColor.g * 0.0f;

OutColor.b = CurrentColor.b * TexelColor.b;
//0.0f = CurrentColor.b * 0.0f;

OutColor.a = CurrentColor.a * TexelColor.a;
//1.0f = CurrentColor.a * 1.0f;

for a white texel
which is something like this:

OutColor.r = CurrentColor.r * TexelColor.r;
//CurrentColor.r = CurrentColor.r * 1.0f;

OutColor.g = CurrentColor.g * TexelColor.g;
//CurrentColor.g = CurrentColor.g * 1.0f;

OutColor.b = CurrentColor.b * TexelColor.b;
//CurrentColor.b = CurrentColor.b * 1.0f;

OutColor.a = CurrentColor.a * TexelColor.a;
//1.0f = CurrentColor.a * 1.0f;

hope that helps, cause i just realized that was written kinda bad lol, feel free to ask questions

cheers
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."

This topic is closed to new replies.

Advertisement