Hi there,

I have a bit of trouble getting transparency and depth to work properly.

I have an image which has a transparent background (transparency in the image below shown with color). So only part of the image is actually opaque. Now I want to draw another object(the blue circle) so that it looks like its behind the first object(the rectangle).

In the image, the first two frames shows what I have got so far. I wish to achieve the effect shown in the 3rd frame. The circle image also has a transparent background like the rectangle.

No matter what I try, I just cant get it to work properly. The circle either ends up behind the rectangle or completely in the front.
Any help or pointers will be much appreciated.



Here is a small part of the code I've written so far:
Code :
/**When cirlce_z > rectangle_z, it is drawn in front
     and behind otherwise
**/
glEnable(GL_DEPTH_TEST);
....
....
 
glEnable(GL_TEXTURE_2D);
/*Drawing the circle first*/
glBindTexture(GL_TEXTURE_2D, circleImage);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	//drawing code
	...
        ...
        ...
 
/*drawing the rectangle last (I've tried the reverse order as well)*/
glBindTexture(GL_TEXTURE_2D, rectImage);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        //drawing code
	...
 
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);