get rid of unused span->start field
[mesa.git] / progs / xdemos / glxgears.c
index a4a9c5e3f44bc5c9567b43c687ce0d86ea87e6cd..75d63e51a2e4f640f08ec127f35c54b3efc47d2f 100644 (file)
@@ -50,7 +50,7 @@
 #include <unistd.h>
 
 /* return current time (in seconds) */
-static int
+static double
 current_time(void)
 {
    struct timeval tv;
@@ -60,16 +60,23 @@ current_time(void)
    struct timezone tz;
    (void) gettimeofday(&tv, &tz);
 #endif
-   return (int) tv.tv_sec;
+   return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
 }
 
 #else /*BENCHMARK*/
 
 /* dummy */
-static int
+static double
 current_time(void)
 {
-   return 0;
+   /* update this function for other platforms! */
+   static double t = 0.0;
+   static int warn = 1;
+   if (warn) {
+      fprintf(stderr, "Warning: current_time() not implemented!!\n");
+      warn = 0;
+   }
+   return t += 1.0;
 }
 
 #endif /*BENCHMARK*/
@@ -85,6 +92,7 @@ static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
 static GLint gear1, gear2, gear3;
 static GLfloat angle = 0.0;
 
+static GLboolean fullscreen = GL_FALSE;        /* Create a single fullscreen window */
 static GLboolean stereo = GL_FALSE;    /* Enable stereo.  */
 static GLfloat eyesep = 5.0;           /* Eye separation. */
 static GLfloat fix_point = 40.0;       /* Fixation point distance.  */
@@ -398,6 +406,12 @@ make_window( Display *dpy, const char *name,
    scrnum = DefaultScreen( dpy );
    root = RootWindow( dpy, scrnum );
 
+   if (fullscreen) {
+      x = 0; y = 0;
+      width = DisplayWidth( dpy, scrnum );
+      height = DisplayHeight( dpy, scrnum );
+   }
+
    if (stereo)
       visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
    else
@@ -416,7 +430,8 @@ make_window( Display *dpy, const char *name,
    attr.border_pixel = 0;
    attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
    attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
-   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+   attr.override_redirect = fullscreen;
+   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
 
    win = XCreateWindow( dpy, root, 0, 0, width, height,
                        0, visinfo->depth, InputOutput,
@@ -491,31 +506,33 @@ event_loop(Display *dpy, Window win)
          }
       }
 
-      /* next frame */
-      angle += 2.0;
-      if (angle > 3600.0)
-       angle -= 3600.0;
-
-      draw();
-      glXSwapBuffers(dpy, win);
-
-      /* calc framerate */
       {
-         static int t0 = -1;
          static int frames = 0;
-         int t = current_time();
+         static double tRot0 = -1.0, tRate0 = -1.0;
+         double dt, t = current_time();
+         if (tRot0 < 0.0)
+            tRot0 = t;
+         dt = t - tRot0;
+         tRot0 = t;
+
+         /* advance rotation for next frame */
+         angle += 70.0 * dt;  /* 70 degrees per second */
+         if (angle > 3600.0)
+             angle -= 3600.0;
 
-         if (t0 < 0)
-            t0 = t;
+         draw();
+         glXSwapBuffers(dpy, win);
 
          frames++;
 
-         if (t - t0 >= 5.0) {
-            GLfloat seconds = t - t0;
+         if (tRate0 < 0.0)
+            tRate0 = t;
+         if (t - tRate0 >= 5.0) {
+            GLfloat seconds = t - tRate0;
             GLfloat fps = frames / seconds;
             printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
                    fps);
-            t0 = t;
+            tRate0 = t;
             frames = 0;
          }
       }
@@ -523,9 +540,21 @@ event_loop(Display *dpy, Window win)
 }
 
 
+static void
+usage(void)
+{
+   printf("Usage:\n");
+   printf("  -display <displayname>  set the display to run on\n");
+   printf("  -stereo                 run in stereo mode\n");
+   printf("  -fullscreen             run in fullscreen mode\n");
+   printf("  -info                   display OpenGL renderer info\n");
+}
+
 int
 main(int argc, char *argv[])
 {
+   const int winWidth = 300, winHeight = 300;
    Display *dpy;
    Window win;
    GLXContext ctx;
@@ -544,8 +573,13 @@ main(int argc, char *argv[])
       else if (strcmp(argv[i], "-stereo") == 0) {
          stereo = GL_TRUE;
       }
-      else
-        printf("Warrning: unknown parameter: %s\n", argv[i]);
+      else if (strcmp(argv[i], "-fullscreen") == 0) {
+         fullscreen = GL_TRUE;
+      }
+      else {
+         usage();
+         return -1;
+      }
    }
 
    dpy = XOpenDisplay(dpyName);
@@ -555,7 +589,7 @@ main(int argc, char *argv[])
       return -1;
    }
 
-   make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &ctx);
+   make_window(dpy, "glxgears", 0, 0, winWidth, winHeight, &win, &ctx);
    XMapWindow(dpy, win);
    glXMakeCurrent(dpy, win, ctx);
 
@@ -568,8 +602,17 @@ main(int argc, char *argv[])
 
    init();
 
+   /* Set initial projection/viewing transformation.
+    * We can't be sure we'll get a ConfigureNotify event when the window
+    * first appears.
+    */
+   reshape(winWidth, winHeight);
+
    event_loop(dpy, win);
 
+   glDeleteLists(gear1, 1);
+   glDeleteLists(gear2, 1);
+   glDeleteLists(gear3, 1);
    glXDestroyContext(dpy, ctx);
    XDestroyWindow(dpy, win);
    XCloseDisplay(dpy);