//*** Animation of a GLUT wireframe cone -- use of idle() callback
// w32ogl Project / Properties: // Must add Linker / Input / Additional Dependencies: opengl32.lib glu32.lib glut32.lib // Must set Linker / Advanced / Entry Point to: mainCRTStartup #include <math.h> #include "glut.h" GLint winWidth=500, winHeight=500; GLfloat theta = 0.0; int doubleb; void init(void) { glClearColor(1.0,1.0,1.0,0.0); glColor3f(1.0,1.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0,1.0,-1.0,1.0,1.0,10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(2.0,2.0,2.0,0.0,0.0,0.0,0.0,0.0,1.0); } void displayd(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,0.0,1.0); //*** display the coordinate axes glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.0,2.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,2.0,0.0); glVertex3f(0.0,0.0,0.0); glVertex3f(2.0,0.0,0.0); glEnd(); glPushMatrix(); // fix coordinate axes glRotatef(theta,0.0,1.0,0.0); // about y axis -- ok //glRotatef(theta,0.0,0.0,1.0); // about z axis -- ok glColor3f(1.0,0.0,0.0); glutWireCone(1.5,1.5,12,6); glPopMatrix(); //delay a bit for (int i=0; i<=9999999; i++); glutSwapBuffers(); } void spinDisplay(void) { theta += 1.0; if (theta >= 360.0) theta -= 360.0; glutPostRedisplay(); } void myReshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0,1.0,-1.0,1.0,1.0,10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(2.0,2.0,2.0,0.0,0.0,0.0,0.0,0.0,1.0); } void main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); doubleb=glutCreateWindow("Animation of a Wireframe Cone"); init(); glutDisplayFunc(displayd); glutReshapeFunc(myReshape); glutIdleFunc(spinDisplay); glutMainLoop(); }