Merge branch 'mesa_7_5_branch'
[mesa.git] / progs / demos / engine.c
index 6040a2f1030dad433aed4d8e28ff65205710df57..3cf311e7782ce139d56c65fa4fd3fef5018231a0 100644 (file)
@@ -5,12 +5,11 @@
  * June 2006
  */
 
-#define GL_GLEXT_PROTOTYPES
-
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <GL/glew.h>
 #include <GL/glut.h>
 #include "readtex.h"
 #include "trackball.h"
@@ -387,7 +386,10 @@ DrawPositionedPiston(const Engine *eng, float crankAngle)
    glPushMatrix();
       glRotatef(-90, 1, 0, 0);
       glTranslatef(0, 0, pos);
-      DrawPiston(eng);
+      if (eng->PistonList)
+         glCallList(eng->PistonList);
+      else
+         DrawPiston(eng);
    glPopMatrix();
 }
 
@@ -555,7 +557,7 @@ SquareWithHole(float squareSize, float holeRadius)
    for (i = 0; i <= 360; i += 5) {
       const float x1 = holeRadius * cos(DEG_TO_RAD(i));
       const float y1 = holeRadius * sin(DEG_TO_RAD(i));
-      float x2, y2;
+      float x2 = 0.0F, y2 = 0.0F;
       if (i > 315 || i <= 45) {
          x2 = squareSize;
          y2 = squareSize * tan(DEG_TO_RAD(i));
@@ -962,6 +964,28 @@ Draw(void)
         glEnable(GL_TEXTURE_2D);
    }
 
+   /* also print out a periodic fps to stdout.  useful for trying to
+    * figure out the performance impact of rendering the string above
+    * with glBitmap.
+    */
+   {
+      static GLint T0 = 0;
+      static GLint Frames = 0;
+      GLint t = glutGet(GLUT_ELAPSED_TIME);
+      
+      Frames++;
+         
+      if (t - T0 >= 5000) {
+         GLfloat seconds = (t - T0) / 1000.0;
+         GLfloat fps = Frames / seconds;
+         printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps);
+         fflush(stdout);
+         T0 = t;
+         Frames = 0;
+      }
+   }
+
+
    glutSwapBuffers();
 }
 
@@ -1288,6 +1312,7 @@ main(int argc, char *argv[])
    glutInitWindowSize(WinWidth, WinHeight);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("OpenGL Engine Demo");
+   glewInit();
    glutReshapeFunc(Reshape);
    glutMouseFunc(Mouse);
    glutMotionFunc(Motion);