Alpha Blending Question

Thanks in advance for any help.

I am trying to implement a simple tree in my game. I am using two rectangles textured with an image of a tree. The rectangles intersect each other, forming a + from above. The problem is the alpha portion of the first rectangle stays even after the second is rendered. Here is a picture: http://68.99.88.179:8080/screenshot.bmp

Here is the code:
// Turn on texture mapping if it’s not already
glEnable(GL_TEXTURE_2D);

// Bind
glBindTexture(GL_TEXTURE_2D, m_Texture);

/* Re-enable Blending */
glEnable( GL_BLEND );
//glBlendFunc(GL_ONE,GL_ONE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glPushMatrix();
glTranslatef(posx,groundy,posz);

glBegin(GL_QUADS); // Start drawing the side as a QUAD
//Assign the texture coordinates and vertices
glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2, 0, 0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, height, 0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(width/2, height, 0);
glTexCoord2f(0.0f, 0.0f); glVertex3f(width/2, 0, 0);
glEnd();

glRotatef(90.0f,0.0f,1.0f,0.0f);

glBegin(GL_QUADS); // Start drawing the side as a QUAD
//Assign the texture coordinates and vertices
glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2, 0, 0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, height, 0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(width/2, height, 0);
glTexCoord2f(0.0f, 0.0f); glVertex3f(width/2, 0, 0);
glEnd();

glPopMatrix();
glDisable( GL_BLEND );

dont use bmp’s but jps’s,pngs etc
anyways
in your case enable alpha testing,
also u can use glDepthMask( GL_FALSE ). but aint as good as the alpha test (u can prolly turn off blending)
enabling alphatest maybe also give a speed increaese

Thanks Zed…

glDepthMask( GL_FALSE ) works great!

Can you elaborate on the Alpha test - how to do it and why it is better?

Thanks
Bob

its faster + alpha the depthvalues gets written in the depthbuffer
see http://developer.nvidia.com/view.asp?IO=Alpha_Test_Tricks

Quick Update - Alpha test does indeed work better - glDepthMask has issues when rendering multiple objects- i.e. no z-buffer so you would need to sort back to front.

Anyway - Thanks again - Alpha test is just what I wanted…:slight_smile: