Jump to content
  • Advertisement
Sign in to follow this  
fram

Transparent work badly

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi to all, please see http://img179.imageshack.us/img179/1490/traspbd9.gif I can't see all objects through the polygon: the number appear hiddend the code is: glDisable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_POLYGON); glVertex3f(xxa0,yya0,zza0); glVertex3f(xxa,yya,zza); glVertex3f(xx00,yy00,zz00); glEnd(); Thanks for any help. Franco

Share this post


Link to post
Share on other sites
Advertisement
The problem is, if you draw your transparent triangle, then you try to draw the number, the part of the number that is behind the triangle will not pass the z-test and so the fragment will be discarded. The solution is to render opaque objects first, and then render transparent objects last.

Share this post


Link to post
Share on other sites
To be more precise, each transparent primitive drawn (after passing the z-test) changes both the color buffer and the zbuffer as any opaque primitive does.

The difference is that opaque primitives replace the color in the color buffer whereas transparent primitives alter the existing color thus making the primitive appear transparent. Both, however, replace the depth value in the zbuffer.

A short example (we consider only one pixel to show the effects):

primitive P1 (red) is opaque, primitive P2 (blue) is transparent with alpha = 0.5.
P1 has depth = 0.6, P2 has depth = 0.55
we use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

First case: draw P1 then P2

draw P1 -> the pixel has color red (1, 0, 0) and depth 0.6
draw P2 -> the pixel now has color red * 0.5 + blue * 0.5 = purple (0.5, 0, 0.5) and depth 0.55.

P2 appears to be transparent since you can "see" P1 through it (the background color is not completely lost).


Second case(your's probably): draw P2 then P1

draw P2 -> the pixel has color blue (0, 0, 1) and depth 0.55.
draw P1 -> the pixel doesn't change since P1 doens't pass the z-test.

P1 disappears even though P2 should be transparent.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!