From http://www.jwz.org/xscreensaver/xscreensaver-5.30.tar.gz
[xscreensaver] / hacks / glx / stairs.c
index 9381f6fadae7246c78943d50e2e4ef1cb367e78e..7fabea1ad32f61af464600e32f1879f7215fd976 100644 (file)
@@ -68,7 +68,13 @@ static const char sccsid[] = "@(#)stairs.c   4.07 97/11/24 xlockmore";
 
 #ifdef USE_GL
 
+#if 0
 #include "e_textures.h"
+#else
+#include "xpm-ximage.h"
+#include "../images/wood.xpm"
+#endif
+
 #include "sphere.h"
 #include "gltrackball.h"
 
@@ -337,45 +343,16 @@ stairs_handle_event (ModeInfo *mi, XEvent *event)
 {
   stairsstruct *sp = &stairs[MI_SCREEN(mi)];
 
-  if (event->xany.type == ButtonPress &&
-      event->xbutton.button == Button1)
-    {
-      sp->button_down_p = True;
-      gltrackball_start (sp->trackball,
-                         event->xbutton.x, event->xbutton.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
-    }
-  else if (event->xany.type == ButtonRelease &&
-           event->xbutton.button == Button1)
-    {
-      sp->button_down_p = False;
-      return True;
-    }
-  else if (event->xany.type == ButtonPress &&
-           (event->xbutton.button == Button4 ||
-            event->xbutton.button == Button5 ||
-            event->xbutton.button == Button6 ||
-            event->xbutton.button == Button7))
-    {
-      gltrackball_mousewheel (sp->trackball, event->xbutton.button, 10,
-                              !!event->xbutton.state);
-      return True;
-    }
-  else if (event->xany.type == MotionNotify &&
-           sp->button_down_p)
-    {
-      gltrackball_track (sp->trackball,
-                         event->xmotion.x, event->xmotion.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
-    }
+  if (gltrackball_event_handler (event, sp->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &sp->button_down_p))
+    return True;
   else if (event->xany.type == KeyPress)
     {
       KeySym keysym;
       char c = 0;
       XLookupString (&event->xkey, &c, 1, &keysym, 0);
-      if (c == ' ')
+      if (c == ' ' || c == '\t')
         {
           gltrackball_reset (sp->trackball);
           return True;
@@ -387,9 +364,9 @@ stairs_handle_event (ModeInfo *mi, XEvent *event)
 
 
 static void
-pinit(void)
+pinit(ModeInfo *mi)
 {
-    int status;
+  /* int status; */
        glClearDepth(1.0);
        glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
@@ -413,6 +390,7 @@ pinit(void)
 
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
+#if 0
     clear_gl_error();
     status = gluBuild2DMipmaps(GL_TEXTURE_2D, 3,
                                WoodTextureWidth, WoodTextureHeight,
@@ -426,6 +404,22 @@ pinit(void)
         exit (1);
       }
     check_gl_error("mipmapping");
+#else
+    {
+      XImage *img = xpm_to_ximage (mi->dpy,
+                                   mi->xgwa.visual,
+                                   mi->xgwa.colormap,
+                                   wood_texture);
+         glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
+                    img->width, img->height, 0,
+                    GL_RGBA,
+                    /* GL_UNSIGNED_BYTE, */
+                    GL_UNSIGNED_INT_8_8_8_8_REV,
+                    img->data);
+      check_gl_error("texture");
+      XDestroyImage (img);
+    }
+#endif
 
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -461,18 +455,19 @@ init_stairs (ModeInfo * mi)
                glDrawBuffer(GL_BACK);
                if (!glIsList(sp->objects))
                        sp->objects = glGenLists(1);
-               pinit();
+               pinit(mi);
        } else {
                MI_CLEARWINDOW(mi);
        }
 
-    sp->trackball = gltrackball_init ();
+    sp->trackball = gltrackball_init (False);
 }
 
 ENTRYPOINT void
 draw_stairs (ModeInfo * mi)
 {
        stairsstruct *sp = &stairs[MI_SCREEN(mi)];
+    GLfloat rot = current_device_rotation();
 
        Display    *display = MI_DISPLAY(mi);
        Window      window = MI_WINDOW(mi);
@@ -486,6 +481,14 @@ draw_stairs (ModeInfo * mi)
 
        glPushMatrix();
 
+    glRotatef(rot, 0, 0, 1);
+    if ((rot >  45 && rot <  135) ||
+        (rot < -45 && rot > -135))
+      {
+        GLfloat s = MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi);
+        glScalef (s, 1/s, 1);
+      }
+
        glTranslatef(0.0, 0.0, -10.0);
 
        if (!MI_IS_ICONIC(mi)) {