From http://www.jwz.org/xscreensaver/xscreensaver-5.39.tar.gz
[xscreensaver] / hacks / glx / gleidescope.c
index 184b4e82ae932314f3cd905ff570cd7e887a4f57..ec333880f236d4771fd426c8c7f7a528dd4d5873 100644 (file)
@@ -77,7 +77,7 @@
                "*useSHM:               True            \n" \
                "*suppressRotationAnimation: True\n" \
 
-# define refresh_gleidescope 0
+# define release_gleidescope 0
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
@@ -86,7 +86,7 @@
 #ifdef USE_GL
 
 #include "colors.h"
-#include "xpm-ximage.h"
+#include "ximage-loader.h"
 #include "grab-ximage.h"
 
 #ifdef GRAB
@@ -105,7 +105,7 @@ static Bool         rotate;                 /* rotate in place */
 static Bool            norotate;               /* no rotate in place */
 static Bool            zoom;                   /* zooming camera */
 static Bool            nozoom;                 /* no zooming camera */
-static char            *image;                 /* name of texture to load */
+static char            *image_str;             /* name of texture to load */
 static int             duration;               /* length of time to display grabbed image */
 
 #define MAX_CAM_SPEED                  1.0
@@ -155,7 +155,7 @@ static argtype vars[] = {
        {&norotate,             "norotate",     "noRotate",     DEF_NOROTATE,   t_Bool},
        {&zoom,                 "zoom",         "Zoom",         DEF_ZOOM,       t_Bool},
        {&nozoom,               "nozoom",       "noZoom",       DEF_NOZOOM,     t_Bool},
-       {&image,                "image",        "Image",        DEF_IMAGE,      t_String},
+       {&image_str,            "image",        "Image",        DEF_IMAGE,      t_String},
        {&duration,             "duration",     "Duration",     DEF_DURATION,           t_Int},
 };
 
@@ -181,9 +181,9 @@ ENTRYPOINT ModeSpecOpt gleidescope_opts = {
 
 #ifdef USE_MODULES
 ModStruct   gleidescope_description = { 
-     "gleidescope", "init_gleidescope", "draw_gleidescope", "release_gleidescope",
-     "draw_gleidescope", "init_gleidescope", NULL, &gleidescope_opts,
-     1000, 1, 2, 1, 4, 1.0, "",
+     "gleidescope", "init_gleidescope", "draw_gleidescope", NULL,
+     "draw_gleidescope", "init_gleidescope", "free_gleidescope",
+     &gleidescope_opts, 1000, 1, 2, 1, 4, 1.0, "",
      "GL Kaleidescope", 0, NULL};
 #endif
 
@@ -882,8 +882,7 @@ setup_file_texture (ModeInfo *mi, char *filename, texture *texture)
        Visual *visual = mi->xgwa.visual;
        char buf[1024];
 
-       Colormap cmap = mi->xgwa.colormap;
-       XImage *image = xpm_file_to_ximage (dpy, visual, cmap, filename);
+       XImage *image = file_to_ximage (dpy, visual, filename);
     if (!image) return False;
 
 #ifdef DEBUG
@@ -925,7 +924,7 @@ setup_texture(ModeInfo * mi, texture *texture)
 {
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
 
-       if (!image || !*image || !strcmp(image, "DEFAULT")) {
+       if (!image_str || !*image_str || !strcmp(image_str, "DEFAULT")) {
     BUILTIN:
                /* no image specified - use system settings */
 #ifdef DEBUG
@@ -933,7 +932,7 @@ setup_texture(ModeInfo * mi, texture *texture)
 #endif
                getSnapshot(mi, texture);
        } else {
-               if (strcmp(image, "GENERATE") == 0) {
+               if (strcmp(image_str, "GENERATE") == 0) {
 #ifdef DEBUG
                        printf("SetupTexture: random_texture\n");
 #endif
@@ -943,7 +942,7 @@ setup_texture(ModeInfo * mi, texture *texture)
 #ifdef DEBUG
                        printf("SetupTexture: file_texture\n");
 #endif
-                       if (! setup_file_texture(mi, image, texture))
+                       if (! setup_file_texture(mi, image_str, texture))
               goto BUILTIN;
                }
        }
@@ -1395,9 +1394,20 @@ draw(ModeInfo * mi)
  */
 ENTRYPOINT void reshape_gleidescope(ModeInfo *mi, int width, int height)
 {
+       gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
        GLfloat         h = (GLfloat) height / (GLfloat) width;
 
-       glViewport(0, 0, (GLint) width, (GLint) height);
+    int y = 0;
+
+    if (width > height * 5) {   /* tiny window: show middle */
+      height = width * 9/16;
+      y = -height/2;
+      h = height / (GLfloat) width;
+    }
+
+       glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(gp->glx_context));
+
+       glViewport(0, y, (GLint) width, (GLint) height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(50.0, 1/h, 0.1, 2000.0);
@@ -1527,12 +1537,7 @@ init_gleidescope(ModeInfo * mi)
        gleidestruct *gp;
        int screen = MI_SCREEN(mi);
 
-       if (gleidescope == NULL) {
-               gleidescope = (gleidestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (gleidestruct));
-               if (gleidescope == NULL) {
-                       return;
-               }
-       }
+       MI_INIT(mi, gleidescope);
        gp = &gleidescope[screen];
        gp->window = MI_WINDOW(mi);
     gp->size = -1;
@@ -1601,27 +1606,17 @@ draw_gleidescope(ModeInfo * mi)
 }
 
 ENTRYPOINT void
-release_gleidescope(ModeInfo * mi)
+free_gleidescope(ModeInfo * mi)
 {
-       if (gleidescope != NULL) {
-               int screen;
-
-               for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-                       gleidestruct *gp = &gleidescope[screen];
+       gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
 
-                       /* acd -  is this needed? */
-                       if (gp->glx_context) {
-                               /* Display lists MUST be freed while their glXContext is current. */
-                               glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context));
+       /* acd -  is this needed? */
+       if (gp->glx_context) {
+               /* Display lists MUST be freed while their glXContext is current. */
+               glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context));
 
-                               /* acd - was code here for freeing things that are no longer in struct */
-                       }
-               }
-               (void) free((void *) gleidescope);
-               gleidescope = NULL;
+               /* acd - was code here for freeing things that are no longer in struct */
        }
-       
-       FreeAllGL(mi);
 }
 
 XSCREENSAVER_MODULE ("Gleidescope", gleidescope)