http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.05.tar.gz
[xscreensaver] / hacks / glx / glblur.c
index 5504e39b92d0d47de88f3538f448d14ffb76cf7c..7d358d127fdb09c908fb4200a4bc047c0eaba7b0 100644 (file)
@@ -1,5 +1,5 @@
 /* glblur --- radial blur using GL textures
- * Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
+ * Copyright (c) 2002-2008 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
  *    http://nehe.gamedev.net/tutorials/lesson.asp?l=36
  */
 
-#include <X11/Intrinsic.h>
-
-extern XtAppContext app;
-
-#define PROGCLASS      "GLBlur"
-#define HACK_INIT      init_glblur
-#define HACK_DRAW      draw_glblur
-#define HACK_RESHAPE   reshape_glblur
-#define HACK_HANDLE_EVENT glblur_handle_event
-#define EVENT_MASK      PointerMotionMask
-#define sws_opts       xlockmore_opts
-
-#define DEF_SPIN        "XYZ"
-#define DEF_WANDER      "True"
-#define DEF_BLURSIZE    "15"
-
-#define DEFAULTS       "*delay:        10000       \n" \
-                       "*showFPS:      False       \n" \
-                       "*fpsSolid:     True        \n" \
-                       "*wireframe:    False       \n" \
-                       "*spin:       " DEF_SPIN   "\n" \
-                       "*wander:     " DEF_WANDER "\n" \
-                       "*blurSize:   " DEF_BLURSIZE "\n" \
-
+#define DEFAULTS       "*delay:    10000 \n" \
+                       "*showFPS:  False \n" \
+                       "*fpsSolid: True  \n"
 
+# define refresh_glblur 0
+# define release_glblur 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -63,8 +44,9 @@ extern XtAppContext app;
 
 #ifdef USE_GL /* whole file */
 
-#include <GL/glu.h>
-
+#define DEF_SPIN        "XYZ"
+#define DEF_WANDER      "True"
+#define DEF_BLURSIZE    "15"
 
 typedef struct metaball metaball;
 
@@ -115,17 +97,17 @@ static XrmOptionDescRec opts[] = {
 };
 
 static argtype vars[] = {
-  {(caddr_t *) &do_spin,   "spin",   "Spin",   DEF_SPIN,   t_String},
-  {(caddr_t *) &do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
-  {(caddr_t *) &blursize,  "blurSize","BlurSize", DEF_BLURSIZE,  t_Int},
+  {&do_spin,   "spin",   "Spin",   DEF_SPIN,   t_String},
+  {&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
+  {&blursize,  "blurSize","BlurSize", DEF_BLURSIZE,  t_Int},
 };
 
-ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
+ENTRYPOINT ModeSpecOpt glblur_opts = {countof(opts), opts, countof(vars), vars, NULL};
 
 
 /* Window management, etc
  */
-void
+ENTRYPOINT void
 reshape_glblur (ModeInfo *mi, int width, int height)
 {
   GLfloat h = (GLfloat) height / (GLfloat) width;
@@ -258,7 +240,10 @@ init_texture (ModeInfo *mi)
   glGenTextures (1, &bp->texture);
   glBindTexture (GL_TEXTURE_2D, bp->texture);
   glTexImage2D (GL_TEXTURE_2D, 0, 4, 128, 128, 0,
-               GL_RGBA, GL_UNSIGNED_BYTE, bp->tex_data);
+               GL_RGBA,
+                /* GL_UNSIGNED_BYTE, */
+                GL_UNSIGNED_INT_8_8_8_8_REV,
+                bp->tex_data);
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 }
@@ -354,13 +339,13 @@ overlay_blur_texture (ModeInfo *mi)
 /* Startup initialization
  */
 
-Bool
+ENTRYPOINT Bool
 glblur_handle_event (ModeInfo *mi, XEvent *event)
 {
   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
 
   if (event->xany.type == ButtonPress &&
-      event->xbutton.button & Button1)
+      event->xbutton.button == Button1)
     {
       bp->button_down_p = True;
       gltrackball_start (bp->trackball,
@@ -369,11 +354,21 @@ glblur_handle_event (ModeInfo *mi, XEvent *event)
       return True;
     }
   else if (event->xany.type == ButtonRelease &&
-           event->xbutton.button & Button1)
+           event->xbutton.button == Button1)
     {
       bp->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 (bp->trackball, event->xbutton.button, 10,
+                              !!event->xbutton.state);
+      return True;
+    }
   else if (event->xany.type == MotionNotify &&
            bp->button_down_p)
     {
@@ -387,7 +382,7 @@ glblur_handle_event (ModeInfo *mi, XEvent *event)
 }
 
 
-void 
+ENTRYPOINT void 
 init_glblur (ModeInfo *mi)
 {
   glblur_configuration *bp;
@@ -449,6 +444,7 @@ init_glblur (ModeInfo *mi)
         if      (*s == 'x' || *s == 'X') spinx = True;
         else if (*s == 'y' || *s == 'Y') spiny = True;
         else if (*s == 'z' || *s == 'Z') spinz = True;
+        else if (*s == '0') ;
         else
           {
             fprintf (stderr,
@@ -496,18 +492,18 @@ init_glblur (ModeInfo *mi)
 
 /* Render one frame
  */
-void
+ENTRYPOINT void
 draw_glblur (ModeInfo *mi)
 {
   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
   Display *dpy = MI_DISPLAY(mi);
   Window window = MI_WINDOW(mi);
 
-  static GLfloat color0[4] = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat color1[4] = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat color2[4] = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat color3[4] = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat spec[4]   = {1.0, 1.0, 1.0, 1.0};
+  GLfloat color0[4] = {0.0, 0.0, 0.0, 1.0};
+  GLfloat color1[4] = {0.0, 0.0, 0.0, 1.0};
+  GLfloat color2[4] = {0.0, 0.0, 0.0, 1.0};
+  GLfloat color3[4] = {0.0, 0.0, 0.0, 1.0};
+  GLfloat spec[4]   = {1.0, 1.0, 1.0, 1.0};
 
   double rx, ry, rz;
   double px, py, pz;
@@ -516,6 +512,8 @@ draw_glblur (ModeInfo *mi)
   if (!bp->glx_context)
     return;
 
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
+
   /* Decide what we're drawing
    */
   if (0 == (random() % 30))
@@ -572,6 +570,7 @@ draw_glblur (ModeInfo *mi)
     glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
 
     glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color0);
+
     glCallList (bp->obj_dlist0);
 
     glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color1);
@@ -634,5 +633,6 @@ draw_glblur (ModeInfo *mi)
   glXSwapBuffers(dpy, window);
 }
 
+XSCREENSAVER_MODULE ("GLBlur", glblur)
 
 #endif /* USE_GL */