From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / hypertorus.c
index 4b81aef9ddb7f9e5e853c6f4be8e3730d6488bab..3ae6aadfc1676be19ae2e2a209d8ae313c8184d6 100644 (file)
@@ -89,7 +89,8 @@ static const char sccsid[] = "@(#)hypertorus.c  1.2 05/09/28 xlockmore";
                             "*showFPS:    False \n" \
                            "*suppressRotationAnimation: True\n" \
 
-# define refresh_hypertorus 0
+# define free_hypertorus 0
+# define release_hypertorus 0
 # include "xlockmore.h"         /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
 # include "xlock.h"             /* from the xlockmore distribution */
@@ -102,7 +103,7 @@ static const char sccsid[] = "@(#)hypertorus.c  1.2 05/09/28 xlockmore";
 
 #ifdef USE_MODULES
 ModStruct   hypertorus_description =
-{"hypertorus", "init_hypertorus", "draw_hypertorus", "release_hypertorus",
+{"hypertorus", "init_hypertorus", "draw_hypertorus", NULL,
  "draw_hypertorus", "change_hypertorus", NULL, &hypertorus_opts,
  25000, 1, 1, 1, 1.0, 4, "",
  "Shows a hypertorus rotating in 4d", 0, NULL};
@@ -743,11 +744,19 @@ static void display_hypertorus(ModeInfo *mi)
 ENTRYPOINT void reshape_hypertorus(ModeInfo *mi, int width, int height)
 {
   hypertorusstruct *hp = &hyper[MI_SCREEN(mi)];
+  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;
+  }
 
   hp->WindW = (GLint)width;
   hp->WindH = (GLint)height;
-  glViewport(0,0,width,height);
-  hp->aspect = (GLfloat)width/(GLfloat)height;
+  glViewport(0,y,width,height);
+  hp->aspect = h;
 }
 
 
@@ -829,13 +838,7 @@ ENTRYPOINT void init_hypertorus(ModeInfo *mi)
 {
   hypertorusstruct *hp;
 
-  if (hyper == NULL)
-  {
-    hyper = (hypertorusstruct *)calloc(MI_NUM_SCREENS(mi),
-                                       sizeof(hypertorusstruct));
-    if (hyper == NULL)
-      return;
-  }
+  MI_INIT(mi, hyper);
   hp = &hyper[MI_SCREEN(mi)];
 
   
@@ -995,33 +998,6 @@ ENTRYPOINT void draw_hypertorus(ModeInfo *mi)
 }
 
 
-/*
- *-----------------------------------------------------------------------------
- *    The display is being taken away from us.  Free up malloc'ed 
- *      memory and X resources that we've alloc'ed.  Only called
- *      once, we must zap everything for every screen.
- *-----------------------------------------------------------------------------
- */
-
-ENTRYPOINT void release_hypertorus(ModeInfo *mi)
-{
-  if (hyper != NULL)
-  {
-    int screen;
-
-    for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
-    {
-      hypertorusstruct *hp = &hyper[screen];
-
-      if (hp->glx_context)
-        hp->glx_context = (GLXContext *)NULL;
-    }
-    (void) free((void *)hyper);
-    hyper = (hypertorusstruct *)NULL;
-  }
-  FreeAllGL(mi);
-}
-
 #ifndef STANDALONE
 ENTRYPOINT void change_hypertorus(ModeInfo *mi)
 {