Sign in to follow this  

Transparent work badly

This topic is 3836 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
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

This topic is 3836 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this