http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.05.tar.gz
[xscreensaver] / hacks / glx / dangerball.c
index fae186b79fefac78cbeba9ff06d0394a4b56a25d..b115d1895af670fd03a56e86669bcda50f333d1f 100644 (file)
@@ -1,4 +1,4 @@
-/* dangerball, Copyright (c) 2001, 2002, 2003 Jamie Zawinski <jwz@jwz.org>
+/* dangerball, Copyright (c) 2001-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
@@ -9,37 +9,13 @@
  * implied warranty.
  */
 
-#include <X11/Intrinsic.h>
-
-extern XtAppContext app;
-
-#define PROGCLASS      "DangerBall"
-#define HACK_INIT      init_ball
-#define HACK_DRAW      draw_ball
-#define HACK_RESHAPE   reshape_ball
-#define HACK_HANDLE_EVENT ball_handle_event
-#define EVENT_MASK      PointerMotionMask
-#define sws_opts       xlockmore_opts
-
-#define DEF_SPIN        "True"
-#define DEF_WANDER      "True"
-#define DEF_SPEED       "0.05"
-
 #define DEFAULTS       "*delay:        30000       \n" \
                        "*count:        30          \n" \
                        "*showFPS:      False       \n" \
                        "*wireframe:    False       \n" \
-                       "*speed:      " DEF_SPEED " \n" \
-                       "*spin:       " DEF_SPIN   "\n" \
-                       "*wander:     " DEF_WANDER "\n" \
-
-
-#define SPIKE_FACES   12  /* how densely to render spikes */
-#define SMOOTH_SPIKES True
-#define SPHERE_SLICES 32  /* how densely to render spheres */
-#define SPHERE_STACKS 16
-
 
+# define refresh_ball 0
+# define release_ball 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -53,7 +29,15 @@ extern XtAppContext app;
 
 #ifdef USE_GL /* whole file */
 
-#include <GL/glu.h>
+
+#define DEF_SPIN        "True"
+#define DEF_WANDER      "True"
+#define DEF_SPEED       "0.05"
+
+#define SPIKE_FACES   12  /* how densely to render spikes */
+#define SMOOTH_SPIKES True
+#define SPHERE_SLICES 32  /* how densely to render spheres */
+#define SPHERE_STACKS 16
 
 typedef struct {
   GLXContext *glx_context;
@@ -94,12 +78,12 @@ static argtype vars[] = {
   {&speed,     "speed",  "Speed",  DEF_SPEED,  t_Float},
 };
 
-ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
+ENTRYPOINT ModeSpecOpt ball_opts = {countof(opts), opts, countof(vars), vars, NULL};
 
 
 /* Window management, etc
  */
-void
+ENTRYPOINT void
 reshape_ball (ModeInfo *mi, int width, int height)
 {
   GLfloat h = (GLfloat) height / (GLfloat) width;
@@ -190,13 +174,13 @@ move_spikes (ModeInfo *mi)
 }
 
 
-Bool
+ENTRYPOINT Bool
 ball_handle_event (ModeInfo *mi, XEvent *event)
 {
   ball_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,
@@ -205,11 +189,21 @@ ball_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)
     {
@@ -223,7 +217,7 @@ ball_handle_event (ModeInfo *mi, XEvent *event)
 }
 
 
-void 
+ENTRYPOINT void 
 init_ball (ModeInfo *mi)
 {
   ball_configuration *bp;
@@ -266,7 +260,7 @@ init_ball (ModeInfo *mi)
 
   {
     double spin_speed   = 10.0;
-    double wander_speed = 0.15;
+    double wander_speed = 0.12;
     double spin_accel   = 2.0;
 
     bp->rot = make_rotator (do_spin ? spin_speed : 0,
@@ -303,7 +297,7 @@ init_ball (ModeInfo *mi)
 }
 
 
-void
+ENTRYPOINT void
 draw_ball (ModeInfo *mi)
 {
   ball_configuration *bp = &bps[MI_SCREEN(mi)];
@@ -311,16 +305,19 @@ draw_ball (ModeInfo *mi)
   Window window = MI_WINDOW(mi);
   int c2;
 
-  static GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat scolor[4] = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat bspec[4]  = {1.0, 1.0, 1.0, 1.0};
-  static GLfloat sspec[4]  = {0.0, 0.0, 0.0, 1.0};
-  static GLfloat bshiny    = 128.0;
-  static GLfloat sshiny    = 0.0;
+  static const GLfloat bspec[4]  = {1.0, 1.0, 1.0, 1.0};
+  static const GLfloat sspec[4]  = {0.0, 0.0, 0.0, 1.0};
+  static const GLfloat bshiny    = 128.0;
+  static const GLfloat sshiny    = 0.0;
+
+  GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
+  GLfloat scolor[4] = {0.0, 0.0, 0.0, 1.0};
 
   if (!bp->glx_context)
     return;
 
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
+
   glShadeModel(GL_SMOOTH);
 
   glEnable(GL_DEPTH_TEST);
@@ -384,4 +381,6 @@ draw_ball (ModeInfo *mi)
   glXSwapBuffers(dpy, window);
 }
 
+XSCREENSAVER_MODULE_2 ("DangerBall", dangerball, ball)
+
 #endif /* USE_GL */