#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define X1 5.5 #define Y1 6.5 #define X2 10.5 #define Y2 12.5 void init(void) { glDisable (GL_DITHER); } static void test2(void) { GLfloat pixelBuf[3]; char buf[12]; static GLfloat vbuf[] = {X1, Y1, X1, Y2, X2, Y1, X2, Y2}; glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); glBegin(GL_POLYGON); glColor3f(0.2, 0.5, 0.8); glVertex2f(X1, Y1); glColor3f(0.2, 0.5, 0.8); glVertex2f(X1, Y2); glColor3f(0.2, 0.5, 0.8); glVertex2f(X2, Y1); glColor3f(0.2, 0.5, 0.8); glVertex2f(X2, Y2); glEnd(); glReadPixels(X1, Y1, 1, 1, GL_RGB, GL_FLOAT, pixelBuf); printf("pixels is: %f %f %f\n", pixelBuf[0], pixelBuf[1], pixelBuf[2]); printf("pixels should be: %f %f %f\n", 0.2, 0.5, 0.8); } void display(void) { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WINDSIZEX, 0, WINDSIZEY); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test2(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }