From http://www.jwz.org/xscreensaver/xscreensaver-5.16.tar.gz
[xscreensaver] / hacks / glx / glschool_gl.c
index 3afe91bdb7725be4d7b68e9ede690e87836d9030..3775b109c5d705d6007f3fc5f6fac4f4d9037e97 100644 (file)
@@ -1,4 +1,4 @@
-/* glschool_gl.c, Copyright (c) 2005-2006 David C. Lambert <dcl@panix.com>
+/* glschool_gl.c, Copyright (c) 2005-2012 David C. Lambert <dcl@panix.com>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 
 #include "sphere.h"
 #include "glschool_gl.h"
+#include "sphere.h"
 #include "tube.h"
 
-static GLUquadricObj   *Quadratic;
-
 void
 drawGoal(double *goal, GLuint goalList)
 {
@@ -28,9 +27,10 @@ drawGoal(double *goal, GLuint goalList)
        glPopMatrix();
 }
 
-void
+int
 drawBoundingBox(BBox *bbox, Bool wire)
 {
+  int polys = 0;
        double          xMin = BBOX_XMIN(bbox);
        double          yMin = BBOX_YMIN(bbox);
        double          zMin = BBOX_ZMIN(bbox);
@@ -49,6 +49,7 @@ drawBoundingBox(BBox *bbox, Bool wire)
        glVertex3f(xMax, yMin, zMin);
        glVertex3f(xMax, yMax, zMin);
        glVertex3f(xMin, yMax, zMin);
+        polys++;
        glEnd();
 
        /* left */
@@ -58,6 +59,7 @@ drawBoundingBox(BBox *bbox, Bool wire)
        glVertex3f(xMin, yMin, zMin);
        glVertex3f(xMin, yMax, zMin);
        glVertex3f(xMin, yMax, zMax);
+        polys++;
        glEnd();
 
        /* right */
@@ -67,6 +69,7 @@ drawBoundingBox(BBox *bbox, Bool wire)
        glVertex3f(xMax, yMin, zMax);
        glVertex3f(xMax, yMax, zMax);
        glVertex3f(xMax, yMax, zMin);
+        polys++;
        glEnd();
 
        /* top */
@@ -76,6 +79,7 @@ drawBoundingBox(BBox *bbox, Bool wire)
        glVertex3f(xMin, yMax, zMax);
        glVertex3f(xMin, yMax, zMin);
        glVertex3f(xMax, yMax, zMin);
+        polys++;
        glEnd();
 
        /* bottom */
@@ -85,71 +89,60 @@ drawBoundingBox(BBox *bbox, Bool wire)
        glVertex3f(xMax, yMin, zMax);
        glVertex3f(xMax, yMin, zMin);
        glVertex3f(xMin, yMin, zMin);
+        polys++;
        glEnd();
 
        if (wire) glLineWidth(1.0);
+
+        return polys;
 }
 
-void
+int
 createBBoxList(BBox *bbox, GLuint *bboxList, int wire)
 {
+  int polys = 0;
        *bboxList = glGenLists(1);
        glNewList(*bboxList, GL_COMPILE);
-       drawBoundingBox(bbox, wire);
+       polys = drawBoundingBox(bbox, wire);
        glEndList();
+        return polys;
 }
 
-#if 1
 void
-createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, int wire)
+createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, int *fish_polys, int *box_polys, int wire)
 {
-       if (Quadratic == (GLUquadricObj *)0) return;
-
-       gluQuadricDrawStyle(Quadratic, (wire ? GLU_LINE : GLU_FILL));
 
-       createBBoxList(bbox, bboxList, wire);
+        int faces = 16;
 
-       *goalList = glGenLists(1);
-       glNewList(*goalList, GL_COMPILE);
-       gluSphere(Quadratic, 5.0, 10, 10);
-       glEndList();
+        *box_polys = 0;
+        *fish_polys = 0;
 
-       *fishList = glGenLists(1);
-       glNewList(*fishList, GL_COMPILE);
-#if 0
-       gluSphere(Quadratic, 2.0, 10, 5);
-       gluCylinder(Quadratic, 2.0, 0.0, 10.0, 10, 5);
-#else
-        gluSphere(Quadratic, 2.0, 3, 2);
-        gluCylinder(Quadratic, 2.0, 0.0, 10.0, 3, 2);
-#endif
-       glEndList();
-}
+        *box_polys +=  createBBoxList(bbox, bboxList, wire);
 
-#else
-void
-createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, Bool wire)
-{
-       createBBoxList(bbox, bboxList, wire);
+        *box_polys = 0;
+        *fish_polys = 0;
 
        *goalList = glGenLists(1);
        glNewList(*goalList, GL_COMPILE);
-       glScalef(10.0, 10.0, 10.0);
-       unit_sphere(10, 10, wire);
+        glScalef (5, 5, 5);
+        *box_polys += unit_sphere (10, 10, wire);
        glEndList();
 
        *fishList = glGenLists(1);
        glNewList(*fishList, GL_COMPILE);
-       glScalef(2.0, 2.0, 2.0);
-       unit_sphere(10, 10, wire);
-       cone(0, 0, 0,
-                0, 0, 5,
-                1, 0, 10,
-                True, False, wire);
+        *fish_polys += cone (0, 0, 0,
+                             0, 0, 10,
+                             2, 0,
+                             faces, True, (faces <= 3), /* cap */
+                             wire);
+        glTranslatef (0, 0, -0.3);
+        glScalef (2, 2, 2);
+        glRotatef (90, 1, 0, 0);
+        if (faces > 3)
+          *fish_polys += unit_sphere (faces, faces, wire);
        glEndList();
 }
 
-#endif
 
 void
 initLights(void)
@@ -203,8 +196,6 @@ initGLEnv(Bool doFog)
 
        initLights();
        if (doFog) initFog();
-
-       Quadratic = gluNewQuadric();
 }
 
 void
@@ -233,7 +224,8 @@ getColorVect(XColor *colors, int index, double *colorVect)
 void
 drawSchool(XColor *colors, School *s,
                   GLuint bboxList, GLuint goalList, GLuint fishList,
-                  int rotCounter, Bool drawGoal_p, Bool drawBBox_p)
+                  int rotCounter, Bool drawGoal_p, Bool drawBBox_p,
+           int fish_polys, int box_polys, unsigned long *polys)
 {
        double                  xVect[3];
        double                  colorVect[3];
@@ -253,6 +245,7 @@ drawSchool(XColor *colors, School *s,
                glDisable(GL_LIGHTING);
                glCallList(bboxList);
                glEnable(GL_LIGHTING);
+                *polys += box_polys;
        }
 
        if (drawGoal_p) drawGoal(SCHOOL_GOAL(s), goalList);
@@ -272,6 +265,7 @@ drawSchool(XColor *colors, School *s,
                        glTranslatef(FISH_X(f), FISH_Y(f), FISH_Z(f));
                        glRotatef(180.0+rotTheta, xVect[0], xVect[1], xVect[2]);
                        glCallList(fishList);
+                        *polys += fish_polys;
                }
                glPopMatrix();
        }