Merge remote branch 'origin/7.8'
[mesa.git] / progs / xdemos / shape.c
index c91b77a3a521bd42599f41dcb643586aa2b9746a..5ff09708be6b71091430ac4b1f2c49255ab7b5e9 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: shape.c,v 1.2 2000/06/27 15:33:44 brianp Exp $ */
 
 /*
  * Example of using the X "shape" extension with OpenGL:  render a spinning
@@ -18,6 +17,9 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
 static int Width=500, Height=500;
 
 static float Xangle = 0.0, Yangle = 0.0;
-static int Redraw = 0;
 static int Sides = 5;
 static int MinSides = 3;
 static int MaxSides = 20;
 
 
+/* return current time (in seconds) */
+static double
+current_time(void)
+{
+   struct timeval tv;
+#ifdef __VMS
+   (void) gettimeofday(&tv, NULL );
+#else
+   struct timezone tz;
+   (void) gettimeofday(&tv, &tz);
+#endif
+   return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
+}
+
+
 /*
  * Draw the OpenGL stuff and do a SwapBuffers.
  */
@@ -140,17 +156,6 @@ static void display(Display *dpy, Window win)
 }
 
 
-/*
- * Called when no events are pending.
- */
-static void idle(void)
-{
-   Xangle += 2.0;
-   Yangle += 3.3;
-   Redraw = 1;
-}
-
-
 /*
  * This is called when we have to recompute the window shape bitmask.
  * We just generate an n-sided regular polygon here but any other shape
@@ -263,11 +268,15 @@ static void event_loop(Display *dpy, Window win)
          }
       }
       else {
-         idle();
-         if (Redraw) {
-            display(dpy, win);
-            Redraw = 0;
-         }
+         static double t0 = -1.0;
+         double dt, t = current_time();
+         if (t0 < 0.0)
+            t0 = t;
+         dt = t - t0;
+         Xangle += 90.0 * dt;  /* 90 degrees per second */
+         Yangle += 70.0 * dt;
+         t0 = t;
+         display(dpy, win);
       }
    }
 }
@@ -374,6 +383,7 @@ int main(int argc, char *argv[])
 
    glXMakeCurrent(dpy, win, glCtx);
 
+   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
    printf("Press ESC to exit.\n");
    printf("Press up/down to change window shape.\n");