Original Post
I was reading the red book. This section http://www.rush3d.com/reference/opengl-redbook-1.1/chapter10.html under Alpha Test. It said that if I render my scene twice, the first time accepting pixels with alpha 1.0 and the second time no equal to 1.0 I can make things go transparent properly. I think I have done everything that it says, yet it still doesn't work. What's happening is the transparent object is showing up through the opaque object when the opaque object should be in front. here are two pics
The first one is what it looks like from a view that works, the box in front is transparent as it should be. The second one is from underneath, it is showing in front of the grey "floor". It should be behind the floor though. here is my code edit: I realised that I was setting depth bits to zero in my window initialisation. So when I put that to 16 it worked. [Edited by - jarro_2783 on July 11, 2006 12:54:31 AM]
The first one is what it looks like from a view that works, the box in front is transparent as it should be. The second one is from underneath, it is showing in front of the grey "floor". It should be behind the floor though. here is my code
for (int i = 0; i < 2; i++) {
if (i == 0) {
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0);
glDepthMask(GL_TRUE);
} else {
glDepthMask(GL_FALSE);
glAlphaFunc(GL_NOTEQUAL, 1.0);
}
//draw a floor
glBegin(GL_QUADS);
glColor3f(0.5, 0.5, 0.5);
glVertex3f(-10.0, -2.0, 10.0);
glVertex3f(10.0, -2.0, 10.0);
glVertex3f(10.0, -2.0, -10.0);
glVertex3f(-10.0, -2.0, -10.0);
glEnd();
//draw some walls
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(-10.0, -2.0, 10.0);
glVertex3f(-10.0, -2.0, -10.0);
glVertex3f(-10.0, 2.0, -10.0);
glVertex3f(-10.0, 2.0, 10.0);
glEnd();
//glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, 1);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glTexCoord2d(0.0f, 0.0f); glVertex3f(-10.0, -2.0, 0.0);
glTexCoord2d(1.0f, 0.0f); glVertex3f(-0.1, -2.0, 0.0);
glTexCoord2d(1.0f, 1.0f); glVertex3f(-0.1, 2.0, 0.0);
glTexCoord2d(0.0f, 1.0f); glVertex3f(-10.0, 2.0, 0.0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
//draw axes
//x
glBegin(GL_LINES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glEnd();
//y
glBegin(GL_LINES);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
//z
glBegin(GL_LINES);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glEnd();
}