Original Post
Hi I am drawing two texture mapped quads, one behind the other and slightly off to the side. The texture is a tree with a transparent background. When I draw the quad closest to the camera first, I get a weird white outline around the non-transparent part of the texture where it overlaps the quad behind it. If I draw them in the reverse order (i.e furthest from the camera first) then all is fine. Here is some code snippets:
void Tree::Render(float x, float y, float z)
{
glPushMatrix();
glTranslatef(x, y, z);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
glBindTexture(GL_TEXTURE_2D, trunkTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_QUADS);
size = 10;
glTexCoord2f(0.0, 0.0);
glVertex3f( -size, size, 0);
glTexCoord2f(1.0, 0.0);
glVertex3f(size, size, 0);
glTexCoord2f(1.0, 1.0);
glVertex3f(size, -size, 0);
glTexCoord2f(0.0, 1.0);
glVertex3f(-size, -size, 0);
glEnd();
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
glPopMatrix();
}
void GLinit(){
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 1.0f, 0.0f;
}
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0);
tree.Render(6, 0, -20);
tree.Render(5, 0, -30);
glutSwapBuffers();
}