changing color of textured quad (solved)
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]
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 ;]
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 ;]
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.
Thanks again.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement