Merge branch 'mesa_7_5_branch'
[mesa.git] / progs / demos / morph3d.c
index 2ce04a3099254deca7ba8bc66540523961d6209f..6aca8270ff515a250505fc44759dbc2b0a674797 100644 (file)
@@ -176,6 +176,7 @@ So the angle is:
 
 static int       mono=0;
 static int       smooth=1;
+static int       anim=1;
 static GLint     WindH, WindW;
 static GLfloat   step=0;
 static GLfloat   seno;
@@ -681,11 +682,19 @@ static void draw ( void ) {
 
   glutSwapBuffers();
 
-  step+=0.05;
 }
 
 static void idle_( void )
 {
+  static double t0 = -1.;
+  double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
+  if (t0 < 0.0)
+     t0 = t;
+  dt = t - t0;
+  t0 = t;
+
+  step += dt;
+
    glutPostRedisplay();
 }
 
@@ -711,11 +720,19 @@ static void key( unsigned char k, int x, int y )
     case '4': object=4; break;
     case '5': object=5; break;
     case ' ': mono^=1; break;
-    case 13: smooth^=1; break;
+    case 's': smooth^=1; break;
+    case 'a':
+       anim^=1;
+       if (anim)
+          glutIdleFunc( idle_ );
+       else
+          glutIdleFunc(NULL);
+       break;
     case 27:
        exit(0);
   }
   pinit();
+  glutPostRedisplay();
 }
 
 static void pinit(void)
@@ -809,7 +826,7 @@ static void pinit(void)
 
 }
 
-static void INIT(void)
+int main(int argc, char **argv)
 {
   printf("Morph 3D - Shows morphing platonic polyhedra\n");
   printf("Author: Marcelo Fernandes Vianna (vianna@cat.cbpf.br)\n\n");
@@ -824,6 +841,7 @@ static void INIT(void)
 
   object=1;
 
+  glutInit(&argc, argv);
   glutInitWindowPosition(0,0);
   glutInitWindowSize(640,480);
 
@@ -871,9 +889,3 @@ static void INIT(void)
   glutMainLoop();
   
 }
-
-int main(int argc, char **argv)
-{
-  INIT();
-  return(0);
-}