# not all polygons are transparent

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

## Recommended Posts

hello, I'm loading a model which uses a .tga file for transparency of tree leafs. It works except a lot of the leaves do not show the leaf behind. All the leaves show the background image OK it's just that the some leaves show the background image but not the leaves behind, so they appear to have a background image imposed on the quad. This is very difficult to explain verbally :s, but hope someone gets what I mean. I'm using 3ds/ase models, do I need to do something with the order of objects before I save the file? EG is leaf z position important and if so how do I get the model in the correct order? Thanks should say I load the models as a displaylist of objects and use the blend command for transparency eg

for(loop=0;loop<model->number_of_objects;loop++)
{

glPushMatrix();
/************set transparency******************/
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);			/*Enable Alpha Blending*/
glEnable(GL_BLEND);

glTranslatef(model->pos.xpos+model->object_list[loop].pos.xpos,
model->pos.ypos+model->object_list[loop].pos.ypos,
model->pos.zpos+model->object_list[loop].pos.zpos);
glScalef(model->scale.xpos,model->scale.ypos,model->scale.zpos);
glRotatef(model->rot.xpos+model->object_list[loop].rot.xpos,1.0f,0.0f,0.0f);
glRotatef(model->rot.ypos+model->object_list[loop].rot.ypos,0.0f,1.0f,0.0f);
glRotatef(model->rot.zpos+model->object_list[loop].rot.zpos,0.0f,0.0f,1.0f);

glCallList(model->object_list[loop].list);
glPopMatrix();
}

glDisable(GL_BLEND);

[\source]



##### Share on other sites
It sounds to me like a depth-buffer-related problem. Transparency and depth buffers don't mix well. Some of the leaves in front are being drawn before some of the leaves behind. This causes nearer values in the depth buffer, which prevent the leaves behind from appearing. The background image and some of the leaves in the back are visible because they just happen to be rendered before the leaves in front of them.

To fix this, you could:

(a) draw the scene in two passes. First draw everything that's opaque, then draw everything that has transparency. This generally works only in scenes where you never have a transparent object in front of another transparent object.

(b) sort the scene so that objects are drawn from most-distant to nearest (this is known as the painter's algorithm). You can combine this with (a) so that you need to sort only transparent objects. If objects overlap, or it isn't feasible to sort them, then this method could be difficult or error-prone. In some cases (particle systems, for example) this method is easy and reliable. Bit of a case-by-case thing, really.

(c) you could switch off alpha blending and use alpha testing instead. You would lose partial transparency and some antialiasing effects, but this gets rid of the problem in a very fast, simple manner. You can switch back to blending for the rest of the scene if you like.

##### Share on other sites
Thanks for that, "Alpha testing" sorted it out. And it whacked my frame rate up as well

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628662
• Total Posts
2984095

• 10
• 9
• 9
• 10
• 21