#include #include #include #include #include static void draw_it(int col) { GLint view[4]; int x0, y0, x1, y1; glGetIntegerv(GL_VIEWPORT, view); glColor3ub(col & 1 ? 255 : 0, col & 2 ? 255 : 0, col & 4 ? 255 : 0); x0 = (3 * view[0] + 1 * view[2]) / 4; y0 = (3 * view[1] + 1 * view[3]) / 4; x1 = (1 * view[0] + 3 * view[2]) / 4; y1 = (1 * view[1] + 3 * view[3]) / 4; glRecti(x0, y0, x1, y1); } static void display(void) { glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT); draw_it(1); glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case '\e': exit(0); break; case 'r': glutPostRedisplay(); break; case 'b': glDrawBuffer(GL_BACK); draw_it(2); break; case 'f': glDrawBuffer(GL_FRONT); draw_it(3); break; case 's': glutSwapBuffers(); break; } } static void reshape(int w, int h) { glViewport(0, 0, w, h); glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, w, 0, h); glPopAttrib(); glMatrixMode(GL_MODELVIEW); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(640, 480); glutCreateWindow("Test"); glutReshapeFunc(reshape); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }