// Computer Graphics - Amir Hesami // This programs shows the effect of using glutIdelFunc() // rotatingrectangle1.cpp #include #include #pragma comment(lib, "opengl32.lib") // Link OpenGL32.lib #pragma comment(lib, "glu32.lib") // Link Glu32.lib #pragma comment(lib, "glut32.lib") // Link Glut32.lib #pragma comment(linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main() #pragma comment(linker, "/subsystem:\"Windows\"" ) // set the entry point to be main() #define DEG_TO_RAD 57.29578 //degree to radian void display(); void idle(); void init(); GLfloat theta = 0.0; int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow("Rotating Rectangle 1"); glutDisplayFunc(display); glutIdleFunc(idle); init(); glutMainLoop(); return 0; } void display() { //Clear the window glClear(GL_COLOR_BUFFER_BIT); //Set the drawing color to red glColor3f(1.0,0.0,0.0); GLfloat theta1 = theta * DEG_TO_RAD; //draw unit square polygon glBegin(GL_POLYGON); glVertex2f(cos(theta1),sin(theta1)); glVertex2f(-sin(theta1),cos(theta1)); glVertex2f(-cos(theta1),-sin(theta1)); glVertex2f(sin(theta1),-cos(theta1)); glEnd(); //Flush the buffer glFlush(); } void init() { //Set the background color glClearColor(1.0,1.0,1.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-2.0,2.0,-2.0,2.0); } void idle() { theta +=2.0; if(theta >360.0) theta -=360; glutPostRedisplay(); }