Original Post
Okay, first off, I apologise for constantly posting so many questions on these forums. I post whenever I get really stuck. In this case hours of experimentation and searching haven't resulted in any success, so I feel it's necessary to ask here. I made a quick sample program to demonstrate the problem, and included a screenshot of it below. What I've done is first drawn an opaque, red quad on a black background (to show how transparent the other shapes are), then drawn two intersecting triangles in front of it, one blue, one yellow, both transparent. The blue triangle is drawn before the yellow. Where the yellow triangle lies in front of the blue one, blue colour still comes through. No problem. But where the blue one lies in front of the yellow, no colour at all is coming up from the yellow triangle (I've even checked the colours using MS Paint to make sure). It may look like a small problem, but it gets much more pronounced for example when I use entire models made up of transparent polygons. I'm really stumped.
Here's the relevant sample of my code too, if it helps: There's probably something stupid about the above code, but I don't know what it is. Many thanks for your attention. [Edited by - Sappharos on March 22, 2009 6:29:51 PM]
Here's the relevant sample of my code too, if it helps:
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable(GL_BLEND); // Turn Blending On
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,-0.5f,-2.0f); // Move Into The Screen 6.0 Units
glBegin (GL_QUADS); // opaque red square
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-0.5, 0.8, 0.0);
glVertex3f( 0.5, 0.8, 0.0);
glVertex3f( 0.5,-0.2, 0.0);
glVertex3f(-0.5,-0.2, 0.0);
glEnd();
glEnable (GL_BLEND);
//glDepthMask(false);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin (GL_TRIANGLES); // transparent blue triangle
glColor4f(0.0, 1.0, 1.0, 0.25);
glVertex3f(0.4, 1.05, 0.0);
glVertex3f(-0.2, 0.65, 0.3);
glVertex3f(0.4, 0.25, 0.0);
glEnd();
glBegin (GL_TRIANGLES); // transparent yellow triangle
glColor4f(1.0, 1.0, 0.0, 0.5);
glVertex3f(-0.4, 0.9, 0.0);
glVertex3f(-0.4, 0.1, 0.0);
glVertex3f(0.2, 0.5, 0.4);
glEnd();
//glDepthMask(true);
glDisable (GL_BLEND);
return TRUE;
}