From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / pipes.c
index 2de9d8a0c9a8257c004819ae532840a3c22eeb49..24f9a2a093bf9602c7699a1481b77ed5cf19d403 100644 (file)
@@ -65,9 +65,10 @@ static const char sccsid[] = "@(#)pipes.c    4.07 97/11/24 xlockmore";
                                        "*size:                 500     \n"                     \
                        "*showFPS:      False   \n"                 \
                        "*fpsSolid:     True    \n"                 \
-                       "*wireframe:    False   \n"
+                       "*wireframe:    False   \n"                 \
+                                       "*suppressRotationAnimation: True\n" \
 
-# define refresh_pipes 0
+# define release_pipes 0
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
@@ -75,7 +76,7 @@ static const char sccsid[] = "@(#)pipes.c     4.07 97/11/24 xlockmore";
 
 #ifdef USE_GL
 
-#ifdef HAVE_COCOA
+#ifdef HAVE_JWXYZ
 # include "jwxyz.h"
 #else
 # include <X11/Xlib.h>
@@ -131,9 +132,9 @@ ENTRYPOINT ModeSpecOpt pipes_opts =
 
 #ifdef USE_MODULES
 ModStruct   pipes_description =
-{"pipes", "init_pipes", "draw_pipes", "release_pipes",
+{"pipes", "init_pipes", "draw_pipes", NULL,
  "draw_pipes",
- "change_pipes", NULL, &pipes_opts,
+ "change_pipes", "free_pipes", &pipes_opts,
  1000, 2, 5, 500, 4, 1.0, "",
  "Shows a selfbuilding pipe system", 0, NULL};
 
@@ -654,12 +655,20 @@ pinit(ModeInfo * mi, int zera)
 ENTRYPOINT void
 reshape_pipes(ModeInfo * mi, int width, int height)
 {
-       glViewport(0, 0, width, (GLint) height);
-       glMatrixMode(GL_PROJECTION);
-       glLoadIdentity();
-       /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
-       gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
-       glMatrixMode(GL_MODELVIEW);
+  double h = (GLfloat) height / (GLfloat) width;  
+  int y = 0;
+
+  if (width > height * 5) {   /* tiny window: show middle */
+    height = width * 9/16;
+    y = -height/2;
+    h = height / (GLfloat) width;
+  }
+  glViewport(0, y, width, (GLint) height);
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
+  gluPerspective(65.0, 1/h, 0.1, 20.0);
+  glMatrixMode(GL_MODELVIEW);
 
   glClear(GL_COLOR_BUFFER_BIT);
 }
@@ -693,11 +702,7 @@ init_pipes (ModeInfo * mi)
        int         screen = MI_SCREEN(mi);
        pipesstruct *pp;
 
-       if (pipes == NULL) {
-               if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
-                                             sizeof (pipesstruct))) == NULL)
-                       return;
-       }
+       MI_INIT (mi, pipes);
        pp = &pipes[screen];
 
        pp->window = MI_WINDOW(mi);
@@ -1168,56 +1173,46 @@ change_pipes (ModeInfo * mi)
 
 
 ENTRYPOINT void
-release_pipes (ModeInfo * mi)
+free_pipes (ModeInfo * mi)
 {
-       if (pipes != NULL) {
-               int         screen;
-
-               for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-                       pipesstruct *pp = &pipes[screen];
-
-                       if (pp->glx_context) {
-
-                               /* Display lists MUST be freed while their glXContext is current. */
-                               glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
-
-                               if (pp->valve)
-                                       glDeleteLists(pp->valve, 1);
-                               if (pp->bolts)
-                                       glDeleteLists(pp->bolts, 1);
-                               if (pp->betweenbolts)
-                                       glDeleteLists(pp->betweenbolts, 1);
-
-                               if (pp->elbowbolts)
-                                       glDeleteLists(pp->elbowbolts, 1);
-                               if (pp->elbowcoins)
-                                       glDeleteLists(pp->elbowcoins, 1);
-
-                               if (pp->guagehead)
-                                       glDeleteLists(pp->guagehead, 1);
-                               if (pp->guageface)
-                                       glDeleteLists(pp->guageface, 1);
-                               if (pp->guagedial)
-                                       glDeleteLists(pp->guagedial, 1);
-                               if (pp->guageconnector)
-                                       glDeleteLists(pp->guageconnector, 1);
-                               if (pp->teapot)
-                                       glDeleteLists(pp->teapot, 1);
-                if (pp->dlists)
-                  {
-                    int i;
-                    for (i = 0; i < pp->dlist_count; i++)
-                      glDeleteLists (pp->dlists[i], 1);
-                    free (pp->dlists);
-                    free (pp->poly_counts);
-                  }
-                       }
-               }
+       pipesstruct *pp = &pipes[MI_SCREEN(mi)];
 
-               (void) free((void *) pipes);
-               pipes = NULL;
+       if (pp->glx_context) {
+
+               /* Display lists MUST be freed while their glXContext is current. */
+               glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
+
+               if (pp->valve)
+                       glDeleteLists(pp->valve, 1);
+               if (pp->bolts)
+                       glDeleteLists(pp->bolts, 1);
+               if (pp->betweenbolts)
+                       glDeleteLists(pp->betweenbolts, 1);
+
+               if (pp->elbowbolts)
+                       glDeleteLists(pp->elbowbolts, 1);
+               if (pp->elbowcoins)
+                       glDeleteLists(pp->elbowcoins, 1);
+
+               if (pp->guagehead)
+                       glDeleteLists(pp->guagehead, 1);
+               if (pp->guageface)
+                       glDeleteLists(pp->guageface, 1);
+               if (pp->guagedial)
+                       glDeleteLists(pp->guagedial, 1);
+               if (pp->guageconnector)
+                       glDeleteLists(pp->guageconnector, 1);
+               if (pp->teapot)
+                       glDeleteLists(pp->teapot, 1);
+        if (pp->dlists)
+          {
+            int i;
+            for (i = 0; i < pp->dlist_count; i++)
+              glDeleteLists (pp->dlists[i], 1);
+            free (pp->dlists);
+            free (pp->poly_counts);
+          }
        }
-       FreeAllGL(mi);
 }
 
 XSCREENSAVER_MODULE ("Pipes", pipes)