From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / noof.c
index 2132b7e8f5b91156d16365b2e18dac15cb0e77b1..ab483f9ab6ce2ff237d3eae5bd7331106e1612e2 100644 (file)
@@ -16,6 +16,8 @@
 #define DEFAULTS       "*delay:        10000       \n" \
                        "*showFPS:      False       \n" \
                        "*fpsSolid:     True        \n" \
+                       "*doubleBuffer: False       \n" \
+                       "*suppressRotationAnimation: True\n" \
 
 # define refresh_noof 0
 # define release_noof 0
@@ -26,6 +28,8 @@
 
 #define N_SHAPES 7
 
+static int dbuf_p = 1;  /* always */
+
 ENTRYPOINT ModeSpecOpt noof_opts = {0, NULL, 0, NULL, NULL};
 
 typedef struct {
@@ -117,10 +121,10 @@ static const float bladeratio[] =
   0.22824, 0.21256, 0.19891, 0.18693, 0.17633, 0.16687,
 };
 
-static void
+static int
 drawleaf(noof_configuration *bp, int l)
 {
-
+  int polys = 0;
   int b, blades;
   float x, y;
   float wobble;
@@ -137,7 +141,7 @@ drawleaf(noof_configuration *bp, int l)
     initshapes(bp, l);      /* let it become reborn as something
                            else */
     bp->tko++;
-    return;
+    return polys;
   } {
     float w1 = sin(bp->geep[l] * 15.3 * M_PI / 180.0);
     wobble = 3.0 + 2.00 * sin(bp->geep[l] * 0.4 * M_PI / 180.0) + 3.94261 * w1;
@@ -174,6 +178,7 @@ drawleaf(noof_configuration *bp, int l)
     glVertex2f(x, y);
     glVertex2f(x, -y);  /* C */
     glVertex2f(0.3, 0.0);  /* D */
+    polys += 2;
     glEnd();
 
     /**
@@ -186,11 +191,13 @@ drawleaf(noof_configuration *bp, int l)
     glVertex2f(x, y);
     glVertex2f(0.3, 0.0);  /* D */
     glVertex2f(x, -y);  /* C */
+    polys += 3;
     glEnd();
     glDisable(GL_BLEND);
 
     glPopMatrix();
   }
+  return polys;
 }
 
 static void
@@ -372,6 +379,7 @@ draw_noof (ModeInfo *mi)
   if (!bp->glx_context)
     return;
   glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
+  mi->polygon_count = 0;
 
   /**
   if((random() & 0xff) == 0x34){
@@ -393,15 +401,14 @@ draw_noof (ModeInfo *mi)
   for (i = 0; i < N_SHAPES; i++) {
     motionUpdate(bp, i);
     colorUpdate(bp, i);
-    drawleaf(bp, i);
+      mi->polygon_count += drawleaf(bp, i);
   }
 
   if (mi->fps_p) do_fps (mi);
   glFinish();
 
-/* For some reason this hack screws up on Cocoa if we try to double-buffer it.
-   It looks fine single-buffered, so let's just do that. */
-/*  glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi)); */
+  if (dbuf_p)
+    glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
 }
 
 
@@ -437,21 +444,13 @@ init_noof (ModeInfo *mi)
   int i;
   noof_configuration *bp;
 
-  if (!bps) {
-    bps = (noof_configuration *)
-      calloc (MI_NUM_SCREENS(mi), sizeof (noof_configuration));
-    if (!bps) {
-      fprintf(stderr, "%s: out of memory\n", progname);
-      exit(1);
-    }
-  }
+  MI_INIT (mi, bps, NULL);
 
   bp = &bps[MI_SCREEN(mi)];
 
   bp->glx_context = init_GL(mi);
 
-  glDrawBuffer(GL_FRONT);
-  glClearColor(0.0, 0.0, 0.0, 1.0);
+  glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
   glEnable(GL_LINE_SMOOTH);
   glShadeModel(GL_FLAT);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);