#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { glClearColor(0.0, 0.0, 0.0, 1.0); glClearDepth(0.0); } static void test(void) { GLfloat buf[4]; glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glClear(GL_DEPTH_BUFFER_BIT); //set the polygon mode to fill glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(25.0, 25.0, 0.00); glVertex3f(25.0, 75.0, 0.00); glVertex3f(75.0, 75.0, 0.5); glVertex3f(75.0, 25.0, 0.5); glEnd(); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.0, -4.0); // dz/dx = 0.25/50 use Scale of -100.0 glColor3f(1.0, 0.0, 0.0); glBegin(GL_POLYGON); glVertex3f(25.0, 25.0, 0.00); glVertex3f(25.0, 75.0, 0.00); glVertex3f(75.0, 75.0, 0.5); glVertex3f(75.0, 25.0, 0.5); glEnd(); glReadPixels(50, 50, 1, 1, GL_RGBA, GL_FLOAT, buf); printf("draw pixel at (50, 50): %f %f %f\n", buf[0], buf[1], buf[2]); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, WINDSIZEX, 0.0, WINDSIZEY, 1.0, -1.0); 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; }