http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.05.tar.gz
[xscreensaver] / hacks / glx / cubenetic.c
index 7fa06e1bc03fe1826806bb1a19dd319665f5d5db..694c147b55b3b4f29869ddd274e4808def5706ee 100644 (file)
@@ -1,4 +1,4 @@
-/* cubenetic, Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
+/* cubenetic, 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
@@ -9,37 +9,13 @@
  * implied warranty.
  */
 
-#include <X11/Intrinsic.h>
-
-extern XtAppContext app;
-
-#define PROGCLASS      "Cubenetic"
-#define HACK_INIT      init_cube
-#define HACK_DRAW      draw_cube
-#define HACK_RESHAPE   reshape_cube
-#define HACK_HANDLE_EVENT cube_handle_event
-#define EVENT_MASK      PointerMotionMask
-#define ccs_opts       xlockmore_opts
-
-#define DEF_SPIN        "XYZ"
-#define DEF_WANDER      "True"
-#define DEF_TEXTURE     "True"
-
-#define DEF_WAVE_COUNT  "3"
-#define DEF_WAVE_SPEED  "80"
-#define DEF_WAVE_RADIUS "512"
-
-#define DEFAULTS       "*delay:        30000       \n" \
+#define DEFAULTS       "*delay:        20000       \n" \
                        "*count:        5           \n" \
                        "*showFPS:      False       \n" \
                        "*wireframe:    False       \n" \
-                       "*spin:       " DEF_SPIN   "\n" \
-                       "*wander:     " DEF_WANDER "\n" \
-                       "*texture:    " DEF_TEXTURE"\n" \
-                       "*waves:      " DEF_WAVE_COUNT  "\n" \
-                       "*waveSpeed:  " DEF_WAVE_SPEED  "\n" \
-                       "*waveRadius: " DEF_WAVE_RADIUS "\n" \
 
+# define refresh_cube 0
+# define release_cube 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -51,7 +27,14 @@ extern XtAppContext app;
 
 #ifdef USE_GL /* whole file */
 
-#include <GL/glu.h>
+
+#define DEF_SPIN        "XYZ"
+#define DEF_WANDER      "True"
+#define DEF_TEXTURE     "True"
+
+#define DEF_WAVE_COUNT  "3"
+#define DEF_WAVE_SPEED  "80"
+#define DEF_WAVE_RADIUS "512"
 
 typedef struct {
   int color;
@@ -113,23 +96,23 @@ static XrmOptionDescRec opts[] = {
   { "+spin",   ".spin",   XrmoptionNoArg, "" },
   { "-wander", ".wander", XrmoptionNoArg, "True" },
   { "+wander", ".wander", XrmoptionNoArg, "False" },
-  {"-texture", ".texture", XrmoptionNoArg, (caddr_t) "true" },
-  {"+texture", ".texture", XrmoptionNoArg, (caddr_t) "false" },
+  {"-texture", ".texture", XrmoptionNoArg, "true" },
+  {"+texture", ".texture", XrmoptionNoArg, "false" },
   {"-waves",       ".waves",      XrmoptionSepArg, 0 },
   {"-wave-speed",  ".waveSpeed",  XrmoptionSepArg, 0 },
   {"-wave-radius", ".waveRadius", XrmoptionSepArg, 0 },
 };
 
 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 *) &do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool},
-  {(caddr_t *) &wave_count, "waves",     "Waves",      DEF_WAVE_COUNT, t_Int},
-  {(caddr_t *) &wave_speed, "waveSpeed", "WaveSpeed",  DEF_WAVE_SPEED, t_Int},
-  {(caddr_t *) &wave_radius,"waveRadius","WaveRadius", DEF_WAVE_RADIUS,t_Int},
+  {&do_spin,   "spin",   "Spin",   DEF_SPIN,   t_String},
+  {&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
+  {&do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool},
+  {&wave_count, "waves",     "Waves",      DEF_WAVE_COUNT, t_Int},
+  {&wave_speed, "waveSpeed", "WaveSpeed",  DEF_WAVE_SPEED, t_Int},
+  {&wave_radius,"waveRadius","WaveRadius", DEF_WAVE_RADIUS,t_Int},
 };
 
-ModeSpecOpt ccs_opts = {countof(opts), opts, countof(vars), vars, NULL};
+ENTRYPOINT ModeSpecOpt cube_opts = {countof(opts), opts, countof(vars), vars, NULL};
 
 
 static void
@@ -190,7 +173,7 @@ unit_cube (Bool wire)
 
 /* Window management, etc
  */
-void
+ENTRYPOINT void
 reshape_cube (ModeInfo *mi, int width, int height)
 {
   GLfloat h = (GLfloat) height / (GLfloat) width;
@@ -324,7 +307,7 @@ init_texture (ModeInfo *mi)
   cc->texture_height = texture_size;
 
   i = texture_size * texture_size * 4;
-  cc->texture = (char *) malloc (i);
+  cc->texture = (unsigned char *) malloc (i);
   memset (cc->texture, 0xFF, i);
 }
 
@@ -343,13 +326,13 @@ shuffle_texture (ModeInfo *mi)
 }
 
 
-Bool
+ENTRYPOINT Bool
 cube_handle_event (ModeInfo *mi, XEvent *event)
 {
   cube_configuration *cc = &ccs[MI_SCREEN(mi)];
 
   if (event->xany.type == ButtonPress &&
-      event->xbutton.button & Button1)
+      event->xbutton.button == Button1)
     {
       cc->button_down_p = True;
       gltrackball_start (cc->trackball,
@@ -358,11 +341,21 @@ cube_handle_event (ModeInfo *mi, XEvent *event)
       return True;
     }
   else if (event->xany.type == ButtonRelease &&
-           event->xbutton.button & Button1)
+           event->xbutton.button == Button1)
     {
       cc->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 (cc->trackball, event->xbutton.button, 10,
+                              !!event->xbutton.state);
+      return True;
+    }
   else if (event->xany.type == MotionNotify &&
            cc->button_down_p)
     {
@@ -376,7 +369,7 @@ cube_handle_event (ModeInfo *mi, XEvent *event)
 }
 
 
-void 
+ENTRYPOINT void 
 init_cube (ModeInfo *mi)
 {
   int i;
@@ -400,9 +393,9 @@ init_cube (ModeInfo *mi)
 
   if (!wire)
     {
-      static GLfloat pos[4] = {1.0, 0.5, 1.0, 0.0};
-      static GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
-      static GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
+      static const GLfloat pos[4] = {1.0, 0.5, 1.0, 0.0};
+      static const GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
+      static const GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
 
       glLightfv(GL_LIGHT0, GL_POSITION, pos);
       glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
@@ -426,6 +419,7 @@ init_cube (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,
@@ -526,7 +520,7 @@ shuffle_cubes (ModeInfo *mi)
 }
 
 
-void
+ENTRYPOINT void
 draw_cube (ModeInfo *mi)
 {
   cube_configuration *cc = &ccs[MI_SCREEN(mi)];
@@ -537,6 +531,8 @@ draw_cube (ModeInfo *mi)
   if (!cc->glx_context)
     return;
 
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(cc->glx_context));
+
   glShadeModel(GL_FLAT);
 
   glEnable(GL_DEPTH_TEST);
@@ -597,4 +593,6 @@ draw_cube (ModeInfo *mi)
   glXSwapBuffers(dpy, window);
 }
 
+XSCREENSAVER_MODULE_2 ("Cubenetic", cubenetic, cube)
+
 #endif /* USE_GL */