#include #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define SIZEW 4 #define SIZEH 4 // Draw function used by many test casses static void Draw() { glBegin(GL_POLYGON); glVertex3f(25.0, 25.0, 0.0); glVertex3f(25.0, 75.0, 0.0); glVertex3f(75.0, 75.0, 0.0); glVertex3f(75.0, 25.0, 0.0); glEnd(); } void init(void) { glClearColor (1,1,1,1); glClearDepth(0.0); glDisable (GL_DITHER); } static void test(void) { GLfloat buf[4]; glDepthFunc(GL_ALWAYS); glEnable(GL_DEPTH_TEST); glColor3f(0.0, 1.0, 0.0); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); glPolygonOffset(0.0, 3000.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Draw(); //Find depth values at different edges of the polygon glReadPixels(25, 50, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &buf[0]); glReadPixels(50, 25, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &buf[1]); glReadPixels(74, 75, 1, 1, GL_DEPTH_COMPONENT,GL_FLOAT,&buf[2]); glReadPixels(40, 75, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &buf[3]); printf("get depth values: %f %f %f %f\n", buf[0], buf[1], buf[2], buf[3]); printf("should above 0\n"); } void display(void) { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, WINDSIZEX, 0, WINDSIZEY, 0, 1); //gluOrtho2D(0, WINDSIZEX, 0, WINDSIZEY); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }