http://www.jwz.org/xscreensaver/xscreensaver-5.12.tar.gz
[xscreensaver] / hacks / glx / dnalogo.c
index b62b3e5efa2990d701d2fd643e06755e19c8d1a5..0051ca5f635b19df440756c1175f30b5bed689e4 100644 (file)
@@ -1,4 +1,4 @@
-/* DNA Logo, Copyright (c) 2001, 2002, 2003 Jamie Zawinski <jwz@jwz.org>
+/* DNA Logo, Copyright (c) 2001-2010 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -64,6 +64,7 @@ typedef struct {
   GLuint helix_list,  helix_list_wire,  helix_list_facetted;
   GLuint gasket_list, gasket_list_wire;
   GLuint frame_list,  frame_list_wire;
+  int polys[7];
 
   int wall_facets;
   int bar_facets;
@@ -112,6 +113,206 @@ ENTRYPOINT ModeSpecOpt logo_opts = {countof(opts), opts, 0, NULL, NULL};
 #define PROBABILITY_SCALE 600
 
 
+#ifdef DXF_OUTPUT_HACK   /* When this is defined, instead of rendering
+                            to the screen, we write a DXF CAD file to stdout.
+                            This is a kludge of shocking magnitude...
+                            Maybe there's some other way to intercept all
+                            glVertex3f calls than with a #define?
+                          */
+
+# define glBegin    dxf_glBegin
+# define glVertex3f dxf_glVertex3f
+# define glEnd      dxf_glEnd
+
+static int dxf_type, dxf_point, dxf_point_total, dxf_layer, dxf_color;
+static GLfloat dxf_quads[4*4];
+
+static void
+dxf_glBegin (int type)
+{
+  dxf_type = type; 
+  dxf_point = 0;
+  dxf_point_total = 0;
+}
+
+static void
+dxf_glVertex3f (GLfloat ox, GLfloat oy, GLfloat oz)
+{
+  int i = 0;
+  GLfloat m[4*4];
+  GLfloat x, y, z;
+
+  /* Transform the point into modelview space. */
+  glGetFloatv (GL_MODELVIEW_MATRIX, m);
+  x = ox * m[0] + oy * m[4] + oz * m[8]  + m[12];
+  y = ox * m[1] + oy * m[5] + oz * m[9]  + m[13];
+  z = ox * m[2] + oy * m[6] + oz * m[10] + m[14];
+
+  dxf_quads[dxf_point*3+0] = x;
+  dxf_quads[dxf_point*3+1] = y;
+  dxf_quads[dxf_point*3+2] = z;
+  dxf_point++;
+  dxf_point_total++;
+
+  switch (dxf_type) {
+  case GL_QUADS:
+    if (dxf_point < 4) return;
+
+    fprintf (stdout, "0\n3DFACE\n8\n%d\n62\n%d\n", dxf_layer, dxf_color);
+    fprintf (stdout, "10\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "20\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "30\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "11\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "21\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "31\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "12\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "22\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "32\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "13\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "23\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "33\n%.6f\n", dxf_quads[i++]);
+    dxf_point = 0;
+    break;
+
+  case GL_QUAD_STRIP:
+    if (dxf_point < 4) return;
+
+    fprintf (stdout, "0\n3DFACE\n8\n%d\n62\n%d\n", dxf_layer, dxf_color);
+    fprintf (stdout, "10\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "20\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "30\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "11\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "21\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "31\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "12\n%.6f\n", dxf_quads[i+3]);  /* funky quad strip */
+    fprintf (stdout, "22\n%.6f\n", dxf_quads[i+4]);  /* vert order: 1243. */
+    fprintf (stdout, "32\n%.6f\n", dxf_quads[i+5]);
+
+    fprintf (stdout, "13\n%.6f\n", dxf_quads[i]);
+    fprintf (stdout, "23\n%.6f\n", dxf_quads[i+1]);
+    fprintf (stdout, "33\n%.6f\n", dxf_quads[i+2]);
+    i += 6;
+
+    dxf_quads[0] = dxf_quads[6];
+    dxf_quads[1] = dxf_quads[7];
+    dxf_quads[2] = dxf_quads[8];
+    dxf_quads[3] = dxf_quads[9];
+    dxf_quads[4] = dxf_quads[10];
+    dxf_quads[5] = dxf_quads[11];
+    dxf_point = 2;
+    break;
+
+  case GL_TRIANGLES:
+  case GL_TRIANGLE_FAN:
+    if (dxf_point < 3) return;
+
+    fprintf (stdout, "0\n3DFACE\n8\n%d\n62\n%d\n", dxf_layer, dxf_color);
+    fprintf (stdout, "10\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "20\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "30\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "11\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "21\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "31\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "12\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "22\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "32\n%.6f\n", dxf_quads[i++]);
+
+    i -= 3;
+    fprintf (stdout, "13\n%.6f\n", dxf_quads[i++]);  /* dup pt 4 as pt 3. */
+    fprintf (stdout, "23\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "33\n%.6f\n", dxf_quads[i++]);
+
+    dxf_point = 0;
+    if (dxf_type == GL_TRIANGLE_FAN)
+      {
+        dxf_quads[3] = dxf_quads[6];
+        dxf_quads[4] = dxf_quads[7];
+        dxf_quads[5] = dxf_quads[8];
+        dxf_point = 2;
+      }
+    break;
+
+  case GL_LINES:
+  case GL_LINE_STRIP:
+  case GL_LINE_LOOP:
+
+    if (dxf_point_total == 1)
+      {
+        dxf_quads[6] = ox;
+        dxf_quads[7] = oy;
+        dxf_quads[8] = oz;
+      }
+
+    if (dxf_point < 2) return;
+
+    fprintf (stdout, "0\nLINE\n8\n%d\n62\n%d\n", dxf_layer, dxf_color);
+
+    fprintf (stdout, "10\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "20\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "30\n%.6f\n", dxf_quads[i++]);
+
+    fprintf (stdout, "11\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "21\n%.6f\n", dxf_quads[i++]);
+    fprintf (stdout, "31\n%.6f\n", dxf_quads[i++]);
+
+    dxf_point = 0;
+    if (dxf_type != GL_LINES)
+      {
+        dxf_quads[0] = dxf_quads[3];
+        dxf_quads[1] = dxf_quads[4];
+        dxf_quads[2] = dxf_quads[5];
+        dxf_point = 1;
+      }
+    break;
+
+  default:
+    abort();
+    break;
+  }
+}
+
+static void
+dxf_glEnd(void)
+{
+  if (dxf_type == GL_LINE_LOOP)  /* close loop */
+    glVertex3f (dxf_quads[6], dxf_quads[7], dxf_quads[8]);
+  dxf_type = -1;
+  dxf_point = 0;
+  dxf_point_total = 0;
+}
+
+
+static void
+dxf_start (void)
+{
+  fprintf (stdout, "0\nSECTION\n2\nHEADER\n0\nENDSEC\n");
+  fprintf (stdout, "0\nSECTION\n2\nENTITIES\n");
+}
+
+static void
+dxf_end (void)
+{
+  fprintf (stdout, "0\nENDSEC\n0\nEOF\n");
+  exit (0);
+}
+
+# define unit_tube dxf_unit_tube
+# define unit_cone dxf_unit_cone
+# define tube_1    dxf_tube_1
+# define tube      dxf_tube
+# define cone      dxf_cone
+# include "tube.c"
+
+#endif /* DXF_OUTPUT_HACK */
+
+
 \f
 /* Calculate the angle (in degrees) between two vectors.
  */
@@ -146,9 +347,10 @@ vector_angle (double ax, double ay, double az,
 /* Make the helix
  */
 
-static void
+static int
 make_helix (logo_configuration *dc, int facetted, int wire)
 {
+  int polys = 0;
   int wall_facets = dc->wall_facets / (facetted ? 10 : 1);
   GLfloat th;
   GLfloat max_th = M_PI * 2 * dc->turns;
@@ -189,6 +391,7 @@ make_helix (logo_configuration *dc, int facetted, int wire)
       glVertex3f( x1, y1,  z1 + h1 + h1off);
       glVertex3f(x1b, y1b, z1 + h1 + h1off);
       glVertex3f(x1b, y1b, z1 - h1 + h1off);
+      polys++;
       glEnd();
     }
 
@@ -242,6 +445,7 @@ make_helix (logo_configuration *dc, int facetted, int wire)
       glNormal3f(x2, y2, 0);
       glVertex3f(x2, y2, z2 + h2 + h2off);
       glVertex3f(x2, y2, z2 - h2 + h2off);
+      polys++;
       glEnd();
 
       /* inner face
@@ -254,6 +458,7 @@ make_helix (logo_configuration *dc, int facetted, int wire)
       glNormal3f(-x2b, -y2b, 0);
       glVertex3f( x2b,  y2b, z2 + h2 + h2off);
       glVertex3f( x2b,  y2b, z2 - h2 + h2off);
+      polys++;
       glEnd();
 
       /* top face
@@ -268,7 +473,7 @@ make_helix (logo_configuration *dc, int facetted, int wire)
       glVertex3f( x2b,  y2b, z2 + h2 + h2off);
       glVertex3f( x1b,  y1b, z1 + h1 + h1off);
       glVertex3f( x1,   y1,  z1 + h1 + h1off);
-
+      polys++;
       glEnd();
 
       /* bottom face
@@ -283,6 +488,7 @@ make_helix (logo_configuration *dc, int facetted, int wire)
       glVertex3f( x1b,  y1b, z1 - h1 + h1off);
       glVertex3f( x2b,  y2b, z2 - h2 + h2off);
       glVertex3f( x2,   y2,  z2 - h2 + h2off);
+      polys++;
       glEnd();
 
       x1 = x2;
@@ -308,14 +514,17 @@ make_helix (logo_configuration *dc, int facetted, int wire)
       glVertex3f(x2,  y2,  z1 + h2 + h2off);
       glVertex3f(x2b, y2b, z1 + h2 + h2off);
       glVertex3f(x2b, y2b, z1 - h2 + h2off);
+      polys++;
       glEnd();
     }
+  return polys;
 }
 
 
-static void
+static int
 make_ladder (logo_configuration *dc, int facetted, int wire)
 {
+  int polys = 0;
   GLfloat th;
   GLfloat max_th = dc->turns * M_PI * 2;
   GLfloat max_z  = dc->turns * dc->turn_spacing;
@@ -342,19 +551,21 @@ make_ladder (logo_configuration *dc, int facetted, int wire)
   if (!dc->clockwise)
     z = -z, z_inc = -z_inc;
 
+  glFrontFace(GL_CCW);
   for (i = 0; i < nbars; i++)
     {
       int facets = dc->bar_facets / (facetted ? 14 : 1);
       if (facets <= 3) facets = 3;
       x = cos (th) * (1 - dc->wall_thickness);
       y = sin (th) * (1 - dc->wall_thickness);
-      tube ( x,  y, z,
-            -x, -y, z,
-             dc->bar_thickness, 0, facets,
-             True, True, wire);
+      polys += tube ( x,  y, z,
+                     -x, -y, z,
+                      dc->bar_thickness, 0, facets,
+                      True, True, wire);
       z  += z_inc;
       th += th_inc;
     }
+  return polys;
 }
 
 
@@ -363,9 +574,10 @@ make_ladder (logo_configuration *dc, int facetted, int wire)
  */
 
 
-static void
+static int
 make_gasket (logo_configuration *dc, int wire)
 {
+  int polys = 0;
   int i;
   int points_size;
   int npoints = 0;
@@ -391,6 +603,10 @@ make_gasket (logo_configuration *dc, int wire)
 
   glPushMatrix();
 
+# ifdef DXF_OUTPUT_HACK
+  if (! wire) res *= 8;
+# endif
+
 # define POINT(r,th) \
     ctrl_r [nctrls] = r, \
     ctrl_th[nctrls] = (th * d2r), \
@@ -438,13 +654,13 @@ make_gasket (logo_configuration *dc, int wire)
   POINT (0.880, 319.74);
   POINT (0.990, 320.08);
 
-  POINT (r4,  338.5);
+  POINT (r4,  338.0);
   if (! wire)
     {
-      POINT (r1a, 338.5);      /* cut-out disc */
-      POINT (r1a, 343.5);
+      POINT (r1a, 338.0);      /* cut-out disc */
+      POINT (r1a, 344.0);
     }
-  POINT (r4,  343.5);
+  POINT (r4,  344.0);
   POINT (r4,  356.0);
 
   POINT (0.872, 356.05);   /* top indentation, left half */
@@ -523,12 +739,14 @@ make_gasket (logo_configuration *dc, int wire)
           glBegin (GL_LINE_LOOP);
           for (i = 0; i < npoints; i++)
             glVertex3f (pointsx0[i], pointsy0[i], z);
+          polys += npoints;
           glEnd();
 
           /* outside edge */
           glBegin (GL_LINE_LOOP);
           for (i = 0; i < npoints; i++)
             glVertex3f (pointsx1[i], pointsy1[i], z);
+          polys += npoints;
           glEnd();
 # else
           for (i = 1; i < npoints; i++)
@@ -540,6 +758,7 @@ make_gasket (logo_configuration *dc, int wire)
               glVertex3f (pointsx1[i-1], pointsy1[i-1], z);
               glEnd();
             }
+          polys += npoints;
 # endif
         }
 #if 1
@@ -553,6 +772,7 @@ make_gasket (logo_configuration *dc, int wire)
           glVertex3f (pointsx1[i], pointsy1[i], -thick2);
           glVertex3f (pointsx1[i], pointsy1[i],  thick2);
         }
+      polys += npoints;
       glEnd();
 #endif
     }
@@ -567,6 +787,7 @@ make_gasket (logo_configuration *dc, int wire)
           glVertex3f (pointsx0[i], pointsy0[i], -thick2);
           glVertex3f (pointsx1[i], pointsy1[i], -thick2);
         }
+      polys += npoints;
       glEnd();
 
       /* bottom */
@@ -578,6 +799,7 @@ make_gasket (logo_configuration *dc, int wire)
           glVertex3f (pointsx0[i], pointsy0[i], thick2);
           glVertex3f (pointsx1[i], pointsy1[i], thick2);
         }
+      polys += npoints;
       glEnd();
 
       /* inside edge */
@@ -589,6 +811,7 @@ make_gasket (logo_configuration *dc, int wire)
           glVertex3f ( pointsx0[i],  pointsy0[i],  thick2);
           glVertex3f ( pointsx0[i],  pointsy0[i], -thick2);
         }
+      polys += npoints;
       glEnd();
 
       /* outside edge */
@@ -641,6 +864,7 @@ make_gasket (logo_configuration *dc, int wire)
                 glVertex3f (xz, yz,  thick2);
               }
           }
+        polys += npoints;
       }
       glEnd();
     }
@@ -651,7 +875,7 @@ make_gasket (logo_configuration *dc, int wire)
     GLfloat th;
     npoints = 0;
 
-    th = 338.5 * d2r;
+    th = 338.0 * d2r;
     pointsx0[npoints] = r1c * cos(th) * dc->gasket_size;
     pointsy0[npoints] = r1c * sin(th) * dc->gasket_size;
     npoints++;
@@ -659,13 +883,12 @@ make_gasket (logo_configuration *dc, int wire)
     pointsy0[npoints] = r4 * sin(th) * dc->gasket_size;
     npoints++;
 
-    th = 343.5 * d2r;
+    th = 344.0 * d2r;
     pointsx0[npoints] = r1c * cos(th) * dc->gasket_size;
     pointsy0[npoints] = r1c * sin(th) * dc->gasket_size;
     npoints++;
     pointsx0[npoints] = r4 * cos(th) * dc->gasket_size;
     pointsy0[npoints] = r4 * sin(th) * dc->gasket_size;
-    npoints++;
 
     if (! wire)
       {
@@ -678,6 +901,7 @@ make_gasket (logo_configuration *dc, int wire)
         glVertex3f (pointsx0[3], pointsy0[3], -thick2);
         glVertex3f (pointsx0[2], pointsy0[2], -thick2);
         glEnd();
+        polys++;
 
         /* back wall */
         glNormal3f (0, 0, 1);
@@ -688,6 +912,7 @@ make_gasket (logo_configuration *dc, int wire)
         glVertex3f (pointsx0[3], pointsy0[3],  thick2);
         glVertex3f (pointsx0[2], pointsy0[2],  thick2);
         glEnd();
+        polys++;
       }
 
     /* top wall */
@@ -701,14 +926,15 @@ make_gasket (logo_configuration *dc, int wire)
     glNormal3f (pointsx0[1], pointsy0[1], 0);
     glVertex3f (pointsx0[1], pointsy0[1], -thick2);
     glEnd();
+    polys++;
 
 
     /* Now make a donut.
      */
     {
-      int nsteps = 12;
+      int nsteps = (wire ? 12 : 64);
       GLfloat r0 = 0.04;
-      GLfloat r1 = 0.060;
+      GLfloat r1 = 0.070;
       GLfloat th, cth, sth;
 
       glPushMatrix ();
@@ -730,6 +956,7 @@ make_gasket (logo_configuration *dc, int wire)
           pointsx1[npoints] = r1 * cth;
           pointsy1[npoints] = r1 * sth;
           npoints++;
+          polys++;
         }
 
       pointsx0[npoints] = pointsx0[0];
@@ -743,19 +970,23 @@ make_gasket (logo_configuration *dc, int wire)
           glBegin (GL_LINE_LOOP);
           for (i = 0; i < npoints; i++)
             glVertex3f (pointsx0[i], pointsy0[i], -thick2);
+          polys += npoints;
           glEnd();
           glBegin (GL_LINE_LOOP);
           for (i = 0; i < npoints; i++)
             glVertex3f (pointsx0[i], pointsy0[i],  thick2);
+          polys += npoints;
           glEnd();
 # if 0
           glBegin (GL_LINE_LOOP);
           for (i = 0; i < npoints; i++)
             glVertex3f (pointsx1[i], pointsy1[i], -thick2);
+          polys += npoints;
           glEnd();
           glBegin (GL_LINE_LOOP);
           for (i = 0; i < npoints; i++)
             glVertex3f (pointsx1[i], pointsy1[i],  thick2);
+          polys += npoints;
           glEnd();
 # endif
         }
@@ -770,6 +1001,7 @@ make_gasket (logo_configuration *dc, int wire)
               glVertex3f (pointsx0[i], pointsy0[i], -thick2);
               glVertex3f (pointsx1[i], pointsy1[i], -thick2);
             }
+          polys += npoints;
           glEnd();
 
           /* bottom */
@@ -781,6 +1013,7 @@ make_gasket (logo_configuration *dc, int wire)
               glVertex3f (pointsx0[i], pointsy0[i],  thick2);
               glVertex3f (pointsx1[i], pointsy1[i],  thick2);
             }
+          polys += npoints;
           glEnd();
         }
 
@@ -793,6 +1026,7 @@ make_gasket (logo_configuration *dc, int wire)
           glVertex3f ( pointsx0[i],  pointsy0[i],  thick2);
           glVertex3f ( pointsx0[i],  pointsy0[i], -thick2);
         }
+      polys += npoints;
       glEnd();
 
       glPopMatrix();
@@ -828,15 +1062,19 @@ make_gasket (logo_configuration *dc, int wire)
         glNormal3f (-1, 0, 0);
         glVertex3f (-w/2, -h/2,  thick2); glVertex3f (-w/2,  h/2,  thick2);
         glVertex3f (-w/2,  h/2, -thick2); glVertex3f (-w/2, -h/2, -thick2);
+        polys++;
         glEnd();
       }
 
     npoints = 0;
-    for (th = 0; th < M_PI; th += (M_PI / 6))
+    for (th = (wire ? 0 : -0.1);
+         th <= M_PI + 0.1;
+         th += (M_PI / (wire ? 5 : 32)))
       {
         pointsx0[npoints] = w/2 * cos(th);
         pointsy0[npoints] = w/2 * sin(th);
         npoints++;
+        polys++;
       }
 
     /* front inside curve */
@@ -846,6 +1084,7 @@ make_gasket (logo_configuration *dc, int wire)
     if (! wire) glVertex3f (0, h/2, -thick2);
     for (i = 0; i < npoints; i++)
       glVertex3f (pointsx0[i], h/2 + pointsy0[i], -thick2);
+    polys += npoints;
     glEnd();
 
     /* front outside curve */
@@ -854,6 +1093,7 @@ make_gasket (logo_configuration *dc, int wire)
     if (! wire) glVertex3f (0, -h/2, -thick2);
     for (i = 0; i < npoints; i++)
       glVertex3f (pointsx0[i], -h/2 - pointsy0[i], -thick2);
+    polys += npoints;
     glEnd();
 
     /* back inside curve */
@@ -863,6 +1103,7 @@ make_gasket (logo_configuration *dc, int wire)
     if (! wire) glVertex3f (0, h/2, thick2);
     for (i = 0; i < npoints; i++)
       glVertex3f (pointsx0[i], h/2 + pointsy0[i], thick2);
+    polys += npoints;
     glEnd();
 
     /* back outside curve */
@@ -871,6 +1112,7 @@ make_gasket (logo_configuration *dc, int wire)
     if (! wire) glVertex3f (0, -h/2, thick2);
     for (i = 0; i < npoints; i++)
       glVertex3f (pointsx0[i], -h/2 - pointsy0[i], thick2);
+    polys += npoints;
     glEnd();
 
     /* inside curve */
@@ -882,6 +1124,7 @@ make_gasket (logo_configuration *dc, int wire)
         glVertex3f (pointsx0[i], h/2 + pointsy0[i],  thick2);
         glVertex3f (pointsx0[i], h/2 + pointsy0[i], -thick2);
       }
+    polys += npoints;
     glEnd();
 
     /* outside curve */
@@ -893,6 +1136,7 @@ make_gasket (logo_configuration *dc, int wire)
         glVertex3f (pointsx0[i], -h/2 - pointsy0[i],  thick2);
         glVertex3f (pointsx0[i], -h/2 - pointsy0[i], -thick2);
       }
+    polys += npoints;
     glEnd();
   }
 
@@ -903,11 +1147,13 @@ make_gasket (logo_configuration *dc, int wire)
   free (normals);
 
   glPopMatrix();
+  return polys;
 }
 
-static void
+static int
 make_frame (logo_configuration *dc, int wire)
 {
+  int polys = 0;
   int i, j;
   GLfloat x[20], y[20];
   GLfloat corner_cut = 0.5;
@@ -952,6 +1198,7 @@ make_frame (logo_configuration *dc, int wire)
             glVertex3f (x[5], y[0], 0); glVertex3f (x[5], y[2], 0); 
             glVertex3f (x[7], y[0], 0); glVertex3f (x[7], y[2], 0);
             glVertex3f (x[8], y[1], 0); glVertex3f (x[8], y[2], 0);
+            polys += 6;
             glEnd ();
             glTranslatef (0.5, 0.5, 0);
             glRotatef (90, 0, 0, 1);
@@ -971,6 +1218,7 @@ make_frame (logo_configuration *dc, int wire)
       glVertex3f (x[4], y[3], 0); glVertex3f (x[4], y[3], dc->frame_depth/2); 
       glVertex3f (x[5], y[2], 0); glVertex3f (x[5], y[2], dc->frame_depth/2); 
       glVertex3f (x[6], y[2], 0); glVertex3f (x[6], y[2], dc->frame_depth/2); 
+      polys += 4;
       glEnd ();
 
       glNormal3f (0, -1, 0);
@@ -979,6 +1227,7 @@ make_frame (logo_configuration *dc, int wire)
       glVertex3f (x[7], y[0], dc->frame_depth/2); 
       glVertex3f (x[1], y[0], dc->frame_depth/2); 
       glVertex3f (x[1], y[0], 0); 
+      polys++;
       glEnd ();
 
       glNormal3f (1, -1, 0);
@@ -987,6 +1236,7 @@ make_frame (logo_configuration *dc, int wire)
       glVertex3f (x[8], y[1], dc->frame_depth/2); 
       glVertex3f (x[7], y[0], dc->frame_depth/2); 
       glVertex3f (x[7], y[0], 0); 
+      polys++;
       glEnd ();
 
       if (wire) 
@@ -1000,6 +1250,7 @@ make_frame (logo_configuration *dc, int wire)
               glVertex3f (x[4], y[3], j*dc->frame_depth/2);
               glVertex3f (x[5], y[2], j*dc->frame_depth/2);
               glVertex3f (x[6], y[2], j*dc->frame_depth/2);
+              polys += 4;
               glEnd ();
             }
         }
@@ -1010,6 +1261,7 @@ make_frame (logo_configuration *dc, int wire)
     }
 
   glPopMatrix();
+  return polys;
 }
 
 
@@ -1165,14 +1417,39 @@ init_logo (ModeInfo *mi)
                                    * dc->speed);
     }
 
+# ifdef DXF_OUTPUT_HACK
+  {
+    dc->frame_depth = dc->gasket_depth;
+    dxf_layer = 1;
+    dxf_color = 3;
+    dxf_start();
+    glPushMatrix();
+    glRotatef(90, 1, 0, 0);
+    glRotatef(90, 0, 0, 1);
+    glPushMatrix();
+    glRotatef(helix_rot, 0, 0, 1);
+    make_ladder (dc, 0, 0);
+    make_helix  (dc, 0, 0);
+    glRotatef (180, 0, 0, 1);
+    make_helix  (dc, 0, 0);
+    glPopMatrix();
+    dxf_layer++;
+    make_gasket (dc, 0);
+    dxf_layer++;
+    make_frame (dc, 0);
+    glPopMatrix();
+    dxf_end();
+  }
+# endif
+
   glPushMatrix();
   dc->helix_list = glGenLists (1);
   glNewList (dc->helix_list, GL_COMPILE);
   glRotatef(helix_rot, 0, 0, 1);
-  if (do_ladder) make_ladder (dc, 0, 0);
-  if (do_helix)  make_helix  (dc, 0, 0);
+  if (do_ladder) dc->polys[0] += make_ladder (dc, 0, 0);
+  if (do_helix)  dc->polys[0] += make_helix  (dc, 0, 0);
   glRotatef(180, 0, 0, 1);
-  if (do_helix)  make_helix  (dc, 0, 0);
+  if (do_helix)  dc->polys[0] += make_helix  (dc, 0, 0);
   glEndList ();
   glPopMatrix();
 
@@ -1180,10 +1457,10 @@ init_logo (ModeInfo *mi)
   dc->helix_list_wire = glGenLists (1);
   glNewList (dc->helix_list_wire, GL_COMPILE);
 /*  glRotatef(helix_rot, 0, 0, 1); wtf? */
-  if (do_ladder) make_ladder (dc, 1, 1);
-  if (do_helix)  make_helix  (dc, 1, 1);
+  if (do_ladder) dc->polys[1] += make_ladder (dc, 1, 1);
+  if (do_helix)  dc->polys[1] += make_helix  (dc, 1, 1);
   glRotatef(180, 0, 0, 1);
-  if (do_helix)  make_helix  (dc, 1, 1);
+  if (do_helix)  dc->polys[1] += make_helix  (dc, 1, 1);
   glEndList ();
   glPopMatrix();
 
@@ -1191,31 +1468,31 @@ init_logo (ModeInfo *mi)
   dc->helix_list_facetted = glGenLists (1);
   glNewList (dc->helix_list_facetted, GL_COMPILE);
   glRotatef(helix_rot, 0, 0, 1);
-  if (do_ladder) make_ladder (dc, 1, 0);
-  if (do_helix)  make_helix  (dc, 1, 0);
+  if (do_ladder) dc->polys[2] += make_ladder (dc, 1, 0);
+  if (do_helix)  dc->polys[2] += make_helix  (dc, 1, 0);
   glRotatef(180, 0, 0, 1);
-  if (do_helix)  make_helix  (dc, 1, 0);
+  if (do_helix)  dc->polys[2] += make_helix  (dc, 1, 0);
   glEndList ();
   glPopMatrix();
 
   dc->gasket_list = glGenLists (1);
   glNewList (dc->gasket_list, GL_COMPILE);
-  if (do_gasket) make_gasket (dc, 0);
+  if (do_gasket) dc->polys[3] += make_gasket (dc, 0);
   glEndList ();
 
   dc->gasket_list_wire = glGenLists (1);
   glNewList (dc->gasket_list_wire, GL_COMPILE);
-  if (do_gasket) make_gasket (dc, 1);
+  if (do_gasket) dc->polys[4] += make_gasket (dc, 1);
   glEndList ();
 
   dc->frame_list = glGenLists (1);
   glNewList (dc->frame_list, GL_COMPILE);
-  if (do_frame) make_frame (dc, 0);
+  if (do_frame) dc->polys[5] += make_frame (dc, 0);
   glEndList ();
 
   dc->frame_list_wire = glGenLists (1);
   glNewList (dc->frame_list_wire, GL_COMPILE);
-  if (do_frame) make_frame (dc, 1);
+  if (do_frame) dc->polys[6] += make_frame (dc, 1);
   glEndList ();
 
   /* When drawing both solid and wireframe objects,
@@ -1328,6 +1605,7 @@ draw_logo (ModeInfo *mi)
   if (!dc->glx_context)
     return;
 
+  mi->polygon_count = 0;
   glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(dc->glx_context));
 
   if (dc->wire_overlay == 0 &&
@@ -1367,16 +1645,23 @@ draw_logo (ModeInfo *mi)
 
       glScalef (1, scale, scale);
       if (wire)
-        glCallList (dc->frame_list_wire);
+        {
+          glCallList (dc->frame_list_wire);
+          mi->polygon_count += dc->polys[6];
+        }
       else if (dc->wire_overlay != 0)
         {
           glCallList (dc->frame_list);
           glDisable (GL_LIGHTING);
           glCallList (dc->frame_list_wire);
+          mi->polygon_count += dc->polys[6];
           if (!wire) glEnable (GL_LIGHTING);
         }
       else
-        glCallList (dc->frame_list);
+        {
+          glCallList (dc->frame_list);
+          mi->polygon_count += dc->polys[5];
+        }
       glPopMatrix();
     }
 
@@ -1406,32 +1691,46 @@ draw_logo (ModeInfo *mi)
       glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS, shininess);
 
       if (wire)
-        glCallList (dc->gasket_list_wire);
+        {
+          glCallList (dc->gasket_list_wire);
+          mi->polygon_count += dc->polys[4];
+        }
       else if (dc->wire_overlay != 0)
         {
           glCallList (dc->gasket_list);
           glDisable (GL_LIGHTING);
           glCallList (dc->gasket_list_wire);
+          mi->polygon_count += dc->polys[4];
           if (!wire) glEnable (GL_LIGHTING);
         }
       else
-        glCallList (dc->gasket_list);
+        {
+          glCallList (dc->gasket_list);
+          mi->polygon_count += dc->polys[3];
+        }
     }
     glPopMatrix();
 
     glRotatef (360 * sin (M_PI/2 * dc->helix_spinnerz.position), 0, 0, 1);
 
     if (wire)
-      glCallList (dc->helix_list_wire);
+      {
+        glCallList (dc->helix_list_wire);
+        mi->polygon_count += dc->polys[1];
+      }
     else if (dc->wire_overlay != 0)
       {
         glCallList (dc->helix_list_facetted);
         glDisable (GL_LIGHTING);
         glCallList (dc->helix_list_wire);
+        mi->polygon_count += dc->polys[2];
         if (!wire) glEnable (GL_LIGHTING);
       }
     else
-      glCallList (dc->helix_list);
+      {
+        glCallList (dc->helix_list);
+        mi->polygon_count += dc->polys[0];
+      }
   }
   glPopMatrix();