/* spinRectangle.c */ /* Purpose - demo program to spin a rectangle around the z-axis, in idle time */ #include #include #include #include #define KEY_ESC 27 /* GLUT doesn't supply this */ /* Global variables */ GLfloat angle = 0.0; GLvoid keyboard(GLubyte key, GLint x, GLint y) { switch (key) { case KEY_ESC: exit(0); /* exit when ESC pressed */ break; } } GLvoid checkError( const char* const label ) { GLenum error; error = glGetError(); while (GL_NO_ERROR != error ) { fprintf(stderr,"%s: %s\n", label, gluErrorString(error) ); error = glGetError(); } } void idle( void ) { static GLint lastTime = 0; GLint time = glutGet(GLUT_ELAPSED_TIME); /* increment angle 20 degrees per second */ angle += 20.0 * (time - lastTime)/1000; lastTime = time; glutPostRedisplay(); } GLvoid display(GLvoid) { /* Do all your OpenGL rendering here */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); /* reset modelview */ glRotatef(angle, 0.0, 0.0, 1.0); glRectf(0.0, 0.0, 1.0, 1.0); /* glutSwapBuffers(); */ /* switch pointers to front and back buffers */ checkError("display"); glFlush(); } void init(void) { /* set background color */ glClearColor(0.4,0.4,0.7,1.0); /* set the 2D orthographic projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0,2.0,-2.0,2.0,-2.0,2.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); /* glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB ); */ glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutIdleFunc(idle); /* glDrawBuffer( GL_BACK ); */ /* draw to back buffer */ glutMainLoop(); return 0; }