#include #include #include #include float spin = 0.0; void display(void) { /* OpenGL Rendering Function */ /* Reset all pixels in buffer to clear color */ glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); /* Rotate buffer x y z */ glRotatef(spin, 0.0, 0.0, 1.0); /* Draw rectangle by coordinate pairs x1,y1 x2,y2 */ glRectf(-25.0, -25.0, 25.0, 25.0); glPopMatrix(); /* Switch buffers displaying rendering to the screen */ glutSwapBuffers(); } void spinDisplay(void) { /* Increase the rotation angle and render */ spin += 2.0; if (spin >= 360.0) { /* Limit the rotation angle to [0,360) */ spin -= 360; } display(); } void myinit(void) { /* Initialize OpenGL default values */ int w,h; /* Window geometry - Width, Height */ w = 400; h = 400; /* OpenGL defaults */ glClearColor(1.0, 0.0, 0.0, 1.0); /* Background Color */ glColor3f(1.0,1.0,0.0); /* Foreground Color */ glViewport(0,0,w,h); /* Viewable area includes entire window geometry */ /* Default orientation */ glOrtho(-50.0, 50.0, -50.0*(float)h/(float)w, 50.0*(float)h/(float)w, -1.0, 1.0); } int main(int argc, char** argv) { /* Initializes GLUT and processes any command line arguments */ glutInit(&argc, argv); /* Create a double buffer using the RGB color scheme */ glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); /* Define Window Geometry */ glutInitWindowSize(400, 400); /* Create window with string argument as title */ glutCreateWindow("My Box"); /* Initialize OpenGL */ myinit(); /* Register the spinDisplay function to run while idle (continuously) */ glutIdleFunc(spinDisplay); /* Register Rendering function */ glutDisplayFunc(display); /* Initialize GLUT Event Handler */ glutMainLoop(); }