View Full Version : Blending Opaque and transparent objects
08-29-2000, 10:24 AM
I'm trying to blend opaque and transparent objects in my scene, and I have a NVidia TNT card.
I am drawing my opque objects first then I am using glDepthFunc(GL_FALSE) to make the Depth Buffer read only when I render my transparent objects.
However, only the following depth function seems to work:
I tried using GL_SRC_ALPHA_MINUS_ONE for the second parameter, but it simply turns blending off. Also the alpha value of my transparent objects doesn't have any effect when I use GL_ONE.
What am I doing wrong?
08-29-2000, 10:25 AM
Oops, I meant
Taken from OpenGL specs :
Transparency is best implemented using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest. Note that this transparency calculation does not require the presence of alpha bitplanes in the frame buffer.
Did you REALLY try yo do GL_SRC_ALPHA_MINUS_ONE or was it GL_ONE_MINUS_SRC_ALPHA ????
In case you really used the first one, I am really surprised coz' I do not even know about a GL extension that defines it... But in case this extension exists, perhaps it is simply not supported by the drivers you have for your TNT...
If you tried the second one and blending turned off, the error is somewhere else and you should post a bit more of your code...
08-30-2000, 11:01 AM
I made a mistake it's
GL_ONE_MINUS_SRC_ALPHA, and not the other way around.
I enable depth testing by calling glEnable(DEPTH_TEST);
I'm posting the part where I turn blending on and off:
// make depth buffer read only
// define the blend function
// enable blending
// draw all transparent objects
// disable blending
// enable depth testing
Since this piece of code is inside a loop (refreshing the scene at regular intervals), I have to make sure that depth testing is enabled and the Depth buffer is writable the next time the loop is kicked off.
I am surprised why GL_ONE_MINUS_SRC_ALPHA doesn't work?
However, if I let the depth buffer enabled, and turn blending on for my entire scene, it starts working!!!
I've looked at what the red book says about this and it has an example which uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), which works in my program, but the transparent objects are really transparent, and the alpha value of my transaparent objects doesn't have any effect! Is it because the destination alpha (of the opaque objects) is 1? If so, why does it work with blending turned on for all objects?
I'd appreciate any help, 'coz I can't think of an explaination!
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.