I believe it is either a hardware or driver problem because my depth testing is not working period. The program below shows a red sphere in back, a green box in the middle, and a blue sphere in front… the order in which they are drawn not the order of their depth relative to the camera.
#include <GL\glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 800, 600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 4/3, 0, 2);
gluLookAt(0, 0, 0, 0, 0, 1, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glColor3f(1, 0, 0);
glTranslatef(.05, .05, .5);
glutSolidSphere(.05, 20, 20);
glPopMatrix();
glPushMatrix();
glColor3f(0, 1, 0);
glTranslatef(0, 0, 1);
glutSolidCube(.1);
glPopMatrix();
glPushMatrix();
glColor3f(0, 0, 1);
glTranslatef(-.1, -.1, 1.5);
glutSolidSphere(.05, 20, 20);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);
glutInitWindowSize(800, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Demonstration");
glEnable(GL_LIGHTING);
GLfloat diffuseLight[] = {.75, .75, .75, 1};
GLfloat lightPosition[] = {-1, -1, -1, 1};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
My graphics card is a GeForce2 MX 400 and I’m using the Nvidia driver version 5.6.7.2 (released in March 2004). I also have Nvidia’s latest stereo driver installed. I’m compiling the code in MS VC++ 6 on a WinXP system.
Has anyone seen this before?
Colby