#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); } static void test(void) { GLfloat buf[10000]; glClear(GL_COLOR_BUFFER_BIT); glColor4f(1.0, 1.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex2i(WINDSIZEX/4, WINDSIZEY/4); glVertex2i(WINDSIZEX*3/4, WINDSIZEY/4); glVertex2i(WINDSIZEX*3/4, WINDSIZEY*3/4); glVertex2i(WINDSIZEX/4, WINDSIZEY*3/4); glEnd(); glReadPixels(WINDSIZEX/2, WINDSIZEY/2, 1, 1, GL_RGB, GL_FLOAT, buf); } void display(void) { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WINDSIZEX, 0, WINDSIZEY); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); } 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; }