/* * single.c * * This program animates a square rotating. The square is drawn into the * using "single" buffer mode. As a result the image tears and flickers. * * Pat Hanrahan 1/97 */ #include "glut.h" static GLfloat spin = 0.0; void Spin(void) { spin = spin + 2.0; if (spin > 360.0) spin = spin - 360.0; glutPostRedisplay(); } void Display(void) { glClearColor (0.0, 0.0, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT); glPushMatrix (); glRotatef (spin, 0.0, 0.0, 1.0); glColor3f (1.0, 1.0, 1.0); glRectf (-25.0, -25.0, 25.0, 25.0); glPopMatrix (); glFinish(); } void Reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w, 50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0); else glOrtho (-50.0*(GLfloat)w/(GLfloat)h, 50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity (); } void Keyboard( unsigned char key, int x, int y ) { #define ESCAPE '\033' if( key == ESCAPE ) exit(0); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowSize(512, 512); glutCreateWindow("Spinning Square (Single Buffer)"); glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutKeyboardFunc(Keyboard); glutIdleFunc(Spin); glutMainLoop(); }