PDA

View Full Version : alpha blending



02-24-2003, 12:28 PM
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.

nexusone
02-24-2003, 01:08 PM
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:
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.

02-24-2003, 01:14 PM
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?

nexusone
02-24-2003, 02:22 PM
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:
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?

SThomas
02-24-2003, 05:03 PM
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 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08) that covers blending.

02-26-2003, 07:27 AM
Just wanted to say thanks for the help.

cheers



Originally posted by nexusone:
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.

nexusone
02-27-2003, 11:33 AM
I wrote a little program that fad between two images...
Drop me an email and I will send it to you.