/* A demonstration of a stencil & depth test bug under * NVIDIA drivers. Start several instances of this program, * kill them all and start some new ones. At some point you'll * get some garbage; that's the bug: the stencil buffer doesn't * get properly initialized. */ #include #include void display() { glClearColor(0.5,0.2,0.2, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); int w = 1; int h = 1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, h, 0, 10000, -10000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glStencilFunc(GL_ALWAYS, 1, 255); glStencilOp(GL_ZERO, GL_ZERO, GL_REPLACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_STENCIL_TEST); glStencilMask(1); glColor3f(0,0,1); glBegin(GL_TRIANGLES); glVertex3f(0,0, 15); glVertex3f(1,0, 5); glVertex3f(0,1, 5); glEnd(); glColor3f(1,1,1); glBegin(GL_TRIANGLES); glVertex3f(0,0, 10); glVertex3f(1,1, 12); glVertex3f(0,1, 13); glEnd(); glStencilFunc(GL_EQUAL, 0, 255); glColor3f(0,1,0); glBegin(GL_TRIANGLES); glVertex3f(0,0, 15); glVertex3f(1,0, 5); glVertex3f(0,1, 5); glEnd(); glPopMatrix(); glutSwapBuffers(); sleep(1); } void idle() { glutPostRedisplay(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL); glutInitWindowSize(1200,900); glutCreateWindow("stenciltest"); glShadeModel(GL_SMOOTH); glutDisplayFunc(display); glutIdleFunc(idle); glutMainLoop(); }