alpha blending

how does one go about changing the opacity of objects in a scene? I have included glEnable(GL_BLEN), and have inserted glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); after every single time the glColor4f(…) was called.

However, nothing seems to change =( and I only have completly opaque objects.

Did you ‘glEnable(GL_BLEND)’?

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
You only need to call it once to set the blend, but important is the order in which you draw the objects.

Most transparent after less transparent.

Also do you have GL_MATERIAL enabled?
then do this:
glDisable(GL_COLOR_MATERIAL); // If material on turn off to set color and alpha
glColor4f( 1.0, 1.0, 1.0, 1.0); Adjust alpha only.
glEnable(GL_COLOR_MATERIAL);

Draw_object();

Originally posted by patrickthenewbie:
[b]how does one go about changing the opacity of objects in a scene? I have included glEnable(GL_BLEN), and have inserted glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); after every single time the glColor4f(…) was called.

However, nothing seems to change =( and I only have completly opaque objects. [/b]

What happens if I cannot determine the order of the objects without significant time costs.

The program is interactive and the user is allowed to change the opacity of the objects on the screen, add new objects, delete other ones, etc. Is there a way to do the opacity thing without ordering?

If you take it on a object to object basis, and I don’t think there is must time cost, since sorting a few variables does not have that much overhead.

I am sure there maybe some other ways to handle, maybe somoe else here will suggest it.

Originally posted by patrickthenewbie:
[b]What happens if I cannot determine the order of the objects without significant time costs.

The program is interactive and the user is allowed to change the opacity of the objects on the screen, add new objects, delete other ones, etc. Is there a way to do the opacity thing without ordering?[/b]

actually, if you want natural looking blending for transparent objects, you should draw based on distance to the camera. further objects first, then closer objects.

you don’t need to sort before you draw, and depending on your scene you might not even notice anything wrong, but if you want correct results you need to sort.

here’s a nehe tutorial that covers blending.

Just wanted to say thanks for the help.

cheers

Originally posted by nexusone:
[b]If you take it on a object to object basis, and I don’t think there is must time cost, since sorting a few variables does not have that much overhead.

I am sure there maybe some other ways to handle, maybe somoe else here will suggest it.

[/b]

I wrote a little program that fad between two images…
Drop me an email and I will send it to you.