From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / cube21.c
index 31a3c6afe2d35dba4f13a26041d4a3e2169f5bfe..a29b47dc7fa29d4dea3c2589a0042f28f590a32f 100644 (file)
@@ -45,7 +45,8 @@
                    "*showFPS:       False         \n" \
                    "*wireframe:     False         \n"
 
-# define refresh_cube21 0
+# define free_cube21 0
+# define release_cube21 0
 #include "xlockmore.h"
 
 #include "gltrackball.h"
@@ -128,7 +129,7 @@ ENTRYPOINT ModeSpecOpt cube21_opts = {countof(opts), opts, countof(vars), vars,
 
 #ifdef USE_MODULES
 ModStruct   cube21_description =
-{ "cube21", "init_cube21", "draw_cube21", "release_cube21",
+{ "cube21", "init_cube21", "draw_cube21", NULL,
   "draw_cube21", "change_cube21", NULL, &cube21_opts,
   25000, 1, 1, 1, 1.0, 4, "",
   "Shows randomly shuffling Cube 21", 0, NULL
@@ -845,9 +846,18 @@ static void init_cp(cube21_conf *cp)
 ENTRYPOINT void reshape_cube21(ModeInfo *mi, int width, int height) 
 {
   cube21_conf *cp = &cube21[MI_SCREEN(mi)];
+  int y = 0;
   if(!height) height = 1;
   cp->ratio = (GLfloat)width/(GLfloat)height;
-  glViewport(0, 0, (GLint) width, (GLint) height);
+
+  if (width > height * 5) {   /* tiny window: show middle */
+    height = width;
+    y = -height/2;
+    cp->ratio = width / (GLfloat) height;
+    cp->posarg = 0;
+  }
+
+  glViewport(0, y, (GLint) width, (GLint) height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(30.0, cp->ratio, 1.0, 100.0);
@@ -869,29 +879,10 @@ cube21_handle_event (ModeInfo *mi, XEvent *event)
 }
 
 
-ENTRYPOINT void release_cube21(ModeInfo *mi) 
-{
-  if (cube21 != NULL) {
-    int screen;
-    for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-      cube21_conf *cp = &cube21[screen];
-      if (cp->glx_context) {
-        cp->glx_context = NULL;
-      }
-    }
-    free((void *)cube21);
-    cube21 = NULL;
-  }
-  FreeAllGL(mi);
-}
-
 ENTRYPOINT void init_cube21(ModeInfo *mi) 
 {
   cube21_conf *cp;
-  if(!cube21) {
-    cube21 = (cube21_conf *)calloc(MI_NUM_SCREENS(mi), sizeof(cube21_conf));
-    if(!cube21) return;
-  }
+  MI_INIT(mi, cube21);
   cp = &cube21[MI_SCREEN(mi)];
 
   cp->trackball = gltrackball_init (False);
@@ -926,7 +917,7 @@ ENTRYPOINT void draw_cube21(ModeInfo * mi)
   mi->polygon_count = 0;
   glXMakeCurrent(display, window, *(cp->glx_context));
   if (!draw_main(mi, cp)) {
-    release_cube21(mi);
+    MI_ABORT(mi);
     return;
   }
   if (MI_IS_FPS(mi)) do_fps (mi);