http://www.jwz.org/xscreensaver/xscreensaver-5.07.tar.gz
[xscreensaver] / hacks / glx / noof.c
index 2132b7e8f5b91156d16365b2e18dac15cb0e77b1..6ec5793e7f50d358976fd69acc9e45da94e95a3a 100644 (file)
 
 #define N_SHAPES 7
 
+/* 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. */
+static int dbuf_p = 0;
+
 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));
 }
 
 
@@ -450,7 +457,7 @@ init_noof (ModeInfo *mi)
 
   bp->glx_context = init_GL(mi);
 
-  glDrawBuffer(GL_FRONT);
+  glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
   glClearColor(0.0, 0.0, 0.0, 1.0);
   glEnable(GL_LINE_SMOOTH);
   glShadeModel(GL_FLAT);