Archived

This topic is now archived and is closed to further replies.

transparent polygons

This topic is 5408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am trying to make some simple polygon objects fade from a set color [glColor3f(1.0f, 0.5f, 0.0f)] to black but transparently so that any other objects can be seen throughthem as they fade away. I am currently using just the three colours (RGB) and reducing them by a set value each frame until they are all zero, but this gives me a solid black object that hides everything under it. Do I need to use the alpha channel and GL_BLEND? can someone point me in the direction of a good tutorial that can help me please.

Share on other sites
Yes, you do need to use the alpha channel and GL_BLEND...

You need to use glColor4f(r, g, b, a); to set your color - don''t change the rgb as you have been doing, just alter the alpha value from 1 (opaque) down to 0 (completely transparent).

You also need to glEnable(GL_BLEND); and there are also several permutations of glBlendFunc(a, b); that you can experiment with, I can''t remember the constants to plug into a and b off hand, but the default values (i.e. don''t call glBlendFunc) should give you a reasonable result...

To find out more, get a copy of the Red Book - it''s got a whole chapter on Blending.

Share on other sites
To make something transparent using blending, you need to use the blend function:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Then all you need to do is plug an alpha value into glColor4f() as mentioned above, and you have your transparency...

Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]

[edited by - iNsAn1tY on May 2, 2003 9:22:02 AM]

Share on other sites
I tried this, but it doesn''t work. I even tried the other blending functions and those won''t do it either. This only makes PURE WHITE be solid and BLACK be translucent. If you wanted to draw blue or green or red, it will make the black invisible, but you will also be able to see thru the colored image(font, for example) Unless you use masking.. Please tell me I''m wrong and/or show me something that proves it, I''ve seen about everything any demo site can offer and nothing gets around the need to use masking.. (except colorkeying maybe?)
I''d really like not to have to draw twice..

Take nehe''s font tutorial and try drawing the font blue, or even take it into photoshop and color the white blue, and you will see what I''m talking about.

Share on other sites
You''re getting Alpha Blending confused with Alpha Testing, if you follow the above instructions and glEnable(GL_BLEND) then you will get the results you require, if you glEnable(GL_ALPHA_TEST) then you will get the effects you described.

Share on other sites
No I''m pretty sure I''ve never touched the alpha test besides to disable it..

Share on other sites
??? It''s off by default...

Share on other sites
Oh, then I guess I don''t, I test with glIsEnabled and if it is enabled my code disables it.. seriously, it doesn''t work for some reason.. Not like masking does

Share on other sites
Sorted :o)

I have used glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) in my InitGL() function. I''m currently using the glEnable(GL_BLEND) and glDisable(GL_BLEND) either side of the code to draw my transparent polys, and it all works brilliantly.. just what I needed..

Thanks to all those who replied..