View Full Version : transparency help...
04-23-2001, 03:59 PM
OKay, I've got a box with the closest wall transparent, but its not working. Before the polygon representing this side is drawn, i declare:
glColor4f(1.0, 1.0, 1.0, .2);
which should be 20% alpha, so the wall is see through, right? But its solid no matter what value I put in for alpha.
I've declared the following blend function in the init() function:
as per a tutorial I was refering to, but it still doesn't work. I've also enabled a depth test:
But all the polygons are overlaid in the order of first -> last declared in the display function. I thought enabling a depth test automatically tested which polygons were closest to the camera and overlaid them on the further away polygons, but its not working this way. And of course no matter what the wall I want to be transparent isn't, no matter what order I draw the wall in, so there are two problems I guess. What am I missing here?
04-23-2001, 04:45 PM
Hi screwtape -
ok, depth test is used to do hidden surface removal among other things in the depth buffer. The depth buffer holds distance values for each pixel, which is then scaled down to a value within the near/far clipping volumn.
so, you want to draw your geometry back to front, or furthest away to closest away, if that makes sense http://www.opengl.org/discussion_boards/ubb/smile.gif
as for blending, did you enable it?
then call glBlendFunc( , ); you might want to try different parameters for this. the most popular are
and then remember to disable it with glDisable(GL_BLEND);
if you have any more troubles, let me know http://www.opengl.org/discussion_boards/ubb/smile.gif
[This message has been edited by Warrior (edited 04-23-2001).]
04-23-2001, 05:59 PM
okay, I understand the depth testing, but is there not a mode that one doesn't necessarily have to create objects from furthest to closest? Like in situations where multiple rotations/reflections don't necessarily keep this order?
Oh, and thanks for the blend function info, but I still have some questions: I've checked the standard man file on my unix system for an explanation of all the different GL_* mode variables, but its not helpful at all. Where can I go to have all the different modes explained online, a compltete tutorial? Finally, say I only want one polygon to be transparent then I enable and disable around only this polygon or just define the individual alpha value for this polygon and keep it enabled for the entire display function? I'm sure that trial and error will tell me but it'd be good to get an explaination too.
Thanks again for the info.
04-23-2001, 06:20 PM
for your first question, yes there are situations like that, for example, like when you have a rotating cube, and some/all sides are blended.
for your second, the Red Book (http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/) is an excellant resource and has a section on blending. Chapter 6 i think.
for your third, i would not enable/disable blending around this polygon. you should minimize the amount of state changes you make. however, if this is all your doing its not going to be that costly.
i would keep blending enabled, and just change glColor4f() around the polygon, setting glColor4f( , , ,1.0f) for all my opaque polygons and a different alpha value for my transparent polygons.
Hope this helps
04-25-2001, 12:49 AM
To find out all the possible combinations for glBlendfunc() (and all other gl* functions) use the msdn library. It's very straightforward and it also has addendums to some of the topics covered in the red book.
Also, Warrior gave you some very good tips which i was going to but there's no need now...The only thing i can add is, for two objects rotating around each other, use alpha blending and depth testing together. You will need to play around with the functions a little bit, but you'll get it eventually.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.