#include #include #define SIZE 50.0 int i; void init(void) { glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 0.0, 0.0); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRectf(-20,-20,20,20); glPopMatrix(); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h && w>0) glOrtho(-SIZE,SIZE,(GLdouble)-h/w*SIZE, (GLdouble)h/w*SIZE,0.0,2*SIZE); else if(h>0) glOrtho((GLdouble)-w/h*SIZE,(GLdouble)w/h*SIZE, -SIZE,SIZE,0.0,2*SIZE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-SIZE); } void keyboard(unsigned char key, int x, int y) { switch(key){ case 27: exit(0); break; case 'f': glutFullScreen(); break; case 'w': glutReshapeWindow(250, 250); break; } } void main (int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(250, 250); glutCreateWindow(argv[0]); init(); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutIdleFunc(display); glutMainLoop(); }