From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / glx / blocktube.c
index b38668b22ac2672e3f9b7515c0c59f34fe9dc30f..51f2f3db758fd2fdc3472cfb5cb089eca43c76cd 100644 (file)
@@ -16,6 +16,7 @@
 #define DEFAULTS        "*delay:       40000           \n" \
                         "*wireframe:    False           \n" \
                        "*showFPS:      False           \n" \
+                       "*suppressRotationAnimation: True\n" \
 
 # define refresh_blocktube 0
 # define blocktube_handle_event 0
@@ -71,6 +72,7 @@ typedef struct {
 
   GLfloat tunnelLength;
   GLfloat tunnelWidth;
+  int polys;
 
 } blocktube_configuration;
 
@@ -132,8 +134,10 @@ static Bool LoadGLTextures(ModeInfo *mi)
             GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, lp->texti->data);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+# ifndef HAVE_JWZGLES /* #### Sphere maps unimplemented */
         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+# endif
     }
     return status;
 }
@@ -197,7 +201,7 @@ static void tick(blocktube_configuration *lp)
     }
 }
 
-static void cube_vertices(float x, float y, float z, int wire);
+static int cube_vertices(float x, float y, float z, int wire);
 
 ENTRYPOINT void reshape_blocktube (ModeInfo *mi, int width, int height);
 
@@ -215,7 +219,6 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi)
         fprintf(stderr, "%s: out of memory\n", progname);
         exit(1);
       }
-      lp = &lps[MI_SCREEN(mi)];
     }
 
     lp = &lps[MI_SCREEN(mi)];
@@ -234,7 +237,7 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi)
 
     lp->block_dlist = glGenLists (1);
     glNewList (lp->block_dlist, GL_COMPILE);
-    cube_vertices(0.15, 1.2, 5.25, wire);
+    lp->polys = cube_vertices(0.15, 1.2, 5.25, wire);
     glEndList ();
 
 #if defined( I_HAVE_XPM )
@@ -260,7 +263,6 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi)
     glShadeModel(GL_SMOOTH);
     glEnable(GL_DEPTH_TEST);
     glEnable(GL_CULL_FACE);
-    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     glClearDepth(1.0f);
 
     if (!do_texture && !wire) {
@@ -320,10 +322,19 @@ ENTRYPOINT void reshape_blocktube (ModeInfo *mi, int width, int height)
     glLoadIdentity();
     gluPerspective(45.0, 1/h, 1.0, 100.0);
     glMatrixMode(GL_MODELVIEW);
+
+# ifdef HAVE_MOBILE    /* Keep it the same relative size when rotated. */
+    {
+      int o = (int) current_device_rotation();
+      if (o != 0 && o != 180 && o != -180)
+        glScalef (1/h, 1/h, 1/h);
+    }
+# endif
 }
 
-static void cube_vertices(float x, float y, float z, int wire)
+static int cube_vertices(float x, float y, float z, int wire)
 {
+    int polygon_count = 0;
     float x2, y2, z2, nv = 0.7;
     x2 = x/2;
     y2 = y/2;
@@ -337,6 +348,7 @@ static void cube_vertices(float x, float y, float z, int wire)
     glTexCoord2f(1.0, 0.0); glVertex3f( x2,  y2,  z2);
     glTexCoord2f(1.0, 1.0); glVertex3f( x2, -y2,  z2);
     glTexCoord2f(0.0, 1.0); glVertex3f(-x2, -y2,  z2);
+    polygon_count++;
     glEnd();
 
     glNormal3f(0, 0, -nv);
@@ -345,6 +357,7 @@ static void cube_vertices(float x, float y, float z, int wire)
     glTexCoord2f(1.0, 1.0); glVertex3f( x2, -y2, -z2);
     glTexCoord2f(0.0, 1.0); glVertex3f( x2,  y2, -z2);
     glTexCoord2f(0.0, 0.0); glVertex3f(-x2,  y2, -z2);
+    polygon_count++;
     glEnd();
 
     glNormal3f(0, nv, 0);
@@ -353,6 +366,7 @@ static void cube_vertices(float x, float y, float z, int wire)
     glTexCoord2f(0.0, 0.0); glVertex3f( x2,  y2, -z2);
     glTexCoord2f(1.0, 0.0); glVertex3f( x2,  y2,  z2);
     glTexCoord2f(1.0, 1.0); glVertex3f(-x2,  y2,  z2);
+    polygon_count++;
     glEnd();
 
     glNormal3f(0, -nv, 0);
@@ -361,9 +375,10 @@ static void cube_vertices(float x, float y, float z, int wire)
     glTexCoord2f(0.0, 1.0); glVertex3f(-x2, -y2,  z2);
     glTexCoord2f(0.0, 0.0); glVertex3f( x2, -y2,  z2);
     glTexCoord2f(1.0, 0.0); glVertex3f( x2, -y2, -z2);
+    polygon_count++;
     glEnd();
 
-    if (wire) return;
+    if (wire) return polygon_count;
 
     glNormal3f(nv, 0, 0);
     glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
@@ -371,6 +386,7 @@ static void cube_vertices(float x, float y, float z, int wire)
     glTexCoord2f(1.0, 1.0); glVertex3f( x2, -y2,  z2);
     glTexCoord2f(0.0, 1.0); glVertex3f( x2,  y2,  z2);
     glTexCoord2f(0.0, 0.0); glVertex3f( x2,  y2, -z2);
+    polygon_count++;
     glEnd();
 
     glNormal3f(-nv, 0, 0);
@@ -379,13 +395,17 @@ static void cube_vertices(float x, float y, float z, int wire)
     glTexCoord2f(1.0, 0.0); glVertex3f(-x2,  y2, -z2);
     glTexCoord2f(1.0, 1.0); glVertex3f(-x2,  y2,  z2);
     glTexCoord2f(0.0, 1.0); glVertex3f(-x2, -y2,  z2);
+    polygon_count++;
     glEnd();
+
+    return polygon_count;
 }
 
 static void draw_block(ModeInfo *mi, entity *ent)
 {
     blocktube_configuration *lp = &lps[MI_SCREEN(mi)];
     glCallList (lp->block_dlist);
+    mi->polygon_count += lp->polys;
 }
 
 ENTRYPOINT void
@@ -400,6 +420,8 @@ draw_blocktube (ModeInfo *mi)
     if (!lp->glx_context)
       return;
 
+    mi->polygon_count = 0;
+
     glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(lp->glx_context));
 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);