another Blending problem

I’m also having trouble with color when I’m blending, whenever I blend or use any color for a polygon, it turns the whole scene into that color, for example, if I have a house drawn, and then I want to draw a blue car in front of it, whenever I specify the color, it changes the whole scene to a shade of blue. I need help. Thanks.

That’s because OpenGL is a state machine. When you tell it to use blue, it will use blue until you tell it to use another color. It won’t just stay blue for the next object, or for the current frame. What I assume your problem is that it does something like so…

You probably have code similar to this…

void Display()
{
DrawHouse();
SetColorBlue();
DrawCar();
}

Now, what this will do is this:
Frame1:
House is draw as white (default color)
Color changed to blue
car drawn as blue

Frame2:
House is drawn as blue (you changed to blue, remember?)
color changed to blue (acutally stayed the same)
Car drawn in blue.

What you should do is specify the color you want to use for each object right before you draw that object. For instance, just setting the color to white before you draw the house will ensure that it is always drawn as white.

I do specify a color. It doesn’t just change the color, it puts a whole shade on everything, even my mapped textures. My code pretty much looks like this

Bind my texture
Draw polygon with mapped texture

translated or do whatever
turn blending on
glColor4f(0.0, 1.0, 1.0, .5);
draw polygon whith a different mapped texture
that will have 50 percent transparency

and then the whole scene will be blended and the tint will be the blue green color.

Which according to your pseudo-code is exactly what is supposed to happen.

[This message has been edited by DFrey (edited 06-29-2001).]

If thats whats supposed to happen, how do you blend certain objects in your scene and not the whole scene. For example if you wanted a water fountain in the middle of your yard and you wanted to be able to see throught the water.

Just disable blending after drawing the object

Originally posted by Z0S007:
[b]
Bind my texture
// Add this…
glColor4f(1.0, 1.0, 1.0, 1.0);
Draw polygon with mapped texture

translated or do whatever
turn blending on
glColor4f(0.0, 1.0, 1.0, .5);
draw polygon whith a different mapped texture
that will have 50 percent transparency

and then the whole scene will be blended and the tint will be the blue green color.[/b]

Look at my edit above. Pretty much exactly what I showed in my previous pseudo code. The default texture environment mode is GL_MODULATE which causes the texture to be combined with the underlying color. You can also set that to GL_REPLACE or GL_DECAL if you don’t want it to do that.

You could always disable blending, but then you textured object would be solid, but would still be affected by the color.

Thanks, the glColor4f(1.0, 1.0, 1.0, 1.0) stopped the color tint, now my only problem is the whole scene is getting blended when I only want one object blended. I have a 3d world that is loaded from a text file, then when you press 1, it draws the object that needs to be blended, and thats when I enable blending, I disable blending when you press 1 again, it gets rid of the object. But when I press 1 it blends the whole world where you can see through the walls. Thanks for all the help people.

Again, you must disable blending after you draw the polygons that are blended so that the polygons that are not supposed to be blended, won’t be. OpenGL is a state machine, and that means it operates in a fashion that conforms to the state that you put it in, and OpenGL will do nothing to change the state you put it in. So if you want to draw a blended polygon, then enable blending, but then if you later want to draw a solid polygon, then you must disable blending, if it was previously turned on.

I’m wondering if you don’t understand that your drawing rountine if being called repeatedly.

[This message has been edited by DFrey (edited 06-29-2001).]

wouldnt setting glcolor3f back to
(1.0,1.0,1.0,1.0)
make the ‘blending’ state to be null, since the alpha component would be max(1.0)? It also sounds more efficient than repeatedly changing blending states.
-bobert

PS: why would you want a trasparent blue car?

Thanks DFrey, I got it fixed. I thought I was disableing blending, but it turned out that on one of the functions that I called, it endabled it at the end, it must have been something I put in there when I first made it.Thanks a bunch. I was really getting frusterated with such a small problem

Bobert, while your idea works, it is in fact generally slower to do that. Because now you are forcing the card to use memory bandwidth unnecessarily.