ftp://ftp.linux.ncsu.edu/mirror/ftp.redhat.com/pub/redhat/linux/enterprise/4/en/os...
[xscreensaver] / hacks / glx / sballs.c
index 9e9b2e3d880a3ed2bda9ab2bfc9a8a971b46c3c8..2eb2bcd92708f030877cd843df44ec741254ce45 100644 (file)
@@ -1,6 +1,6 @@
 /* sballs --- balls spinning like crazy in GL */
 
-#if !defined( lint ) && !defined( SABER )
+#if 0
 static const char sccsid[] = "@(#)sballs.c     5.02 2001/03/10 xlockmore";
 #endif
 
@@ -23,7 +23,7 @@ static const char sccsid[] = "@(#)sballs.c    5.02 2001/03/10 xlockmore";
  * Mustata Bogdan (LoneRunner) <lonerunner@planetquake.com>
  * and can be found at http://www.cfxweb.net/lonerunner/
  *
- * Eric Lassauge  (November-07-2000) <lassauge@mail.dotcom.fr>
+ * Eric Lassauge  (November-07-2000) <lassauge@users.sourceforge.net>
  *                                 http://lassauge.free.fr/linux.html
  *
  * REVISION HISTORY:
@@ -46,9 +46,9 @@ static const char sccsid[] = "@(#)sballs.c    5.02 2001/03/10 xlockmore";
 #define HACK_DRAW      draw_sballs
 #define HACK_RESHAPE   reshape_sballs
 #define sballs_opts    xlockmore_opts
-#define DEFAULTS       "*delay:        10000 \n" \
+#define DEFAULTS       "*delay:        30000 \n" \
                        "*size:             0 \n" \
-                       "*cycles:          10 \n" \
+                       "*cycles:           4 \n" \
                        "*object:           0 \n" \
                        "*trackmouse:   False \n" \
                        "*showFPS:      False \n" \
@@ -74,50 +74,58 @@ static const char sccsid[] = "@(#)sballs.c  5.02 2001/03/10 xlockmore";
 
 #if defined( USE_XPM ) || defined( USE_XPMINC ) || defined( HAVE_XPM )
 /* USE_XPM & USE_XPMINC in xlock mode ; HAVE_XPM in xscreensaver mode */
-#include "xpm-ximage.h"
-#define I_HAVE_XPM
-
-#ifdef STANDALONE
-#include "../images/sball.xpm"
-#include "../images/sball-bg.xpm"
-#else /* !STANDALONE */
-#include "pixmaps/sball.xpm"
-#include "pixmaps/sball-bg.xpm"
-#endif /* !STANDALONE */
+# include "xpm-ximage.h"
+# define I_HAVE_XPM
+
+# ifdef STANDALONE
+
+#  ifdef __GNUC__
+   __extension__ /* don't warn about "string length is greater than the length
+                    ISO C89 compilers are required to support" when including
+                    the following XPM file... */
+#  endif
+#  include "../images/sball.xpm"
+#  ifdef __GNUC__
+   __extension__
+#  endif
+#  include "../images/sball-bg.xpm"
+# else /* !STANDALONE */
+#  include "pixmaps/sball.xpm"
+#  include "pixmaps/sball-bg.xpm"
+# endif /* !STANDALONE */
 #endif /* HAVE_XPM */
 
 /* Manage option vars */
 #define DEF_TEXTURE    "True"
 #define DEF_TRACKMOUSE  "False"
-#define DEF_OBJECT     "2"
-#define DEF_OBJECT_INDX        2
+#define DEF_OBJECT     "0"
 static Bool do_texture;
 static Bool do_trackmouse;
 static int  object;
 static int  spheres;
 
 static XrmOptionDescRec opts[] = {
-    {(char *) "-texture", (char *) ".sballs.texture", XrmoptionNoArg, (caddr_t) "on"},
-    {(char *) "+texture", (char *) ".sballs.texture", XrmoptionNoArg, (caddr_t) "off"},
-    {(char *) "-trackmouse", (char *) ".sballs.trackmouse", XrmoptionNoArg, (caddr_t) "on"},
-    {(char *) "+trackmouse", (char *) ".sballs.trackmouse", XrmoptionNoArg, (caddr_t) "off"},
-    {(char *) "-object", (char *) ".sballs.object", XrmoptionSepArg, (caddr_t) NULL},
+    {"-texture", ".sballs.texture", XrmoptionNoArg, "on"},
+    {"+texture", ".sballs.texture", XrmoptionNoArg, "off"},
+    {"-trackmouse", ".sballs.trackmouse", XrmoptionNoArg, "on"},
+    {"+trackmouse", ".sballs.trackmouse", XrmoptionNoArg, "off"},
+    {"-object", ".sballs.object", XrmoptionSepArg, 0},
 
 };
 
 static argtype vars[] = {
-    {(caddr_t *) & do_texture, (char *) "texture", (char *) "Texture", (char *) DEF_TEXTURE, t_Bool},
-    {(caddr_t *) & do_trackmouse, (char *) "trackmouse", (char *) "TrackMouse", (char *) DEF_TRACKMOUSE, t_Bool},
-    {(caddr_t *) & object, (char *) "object", (char *) "Object", (char *) DEF_OBJECT, t_Int},
+    {&do_texture,    "texture",    "Texture",    DEF_TEXTURE,    t_Bool},
+    {&do_trackmouse, "trackmouse", "TrackMouse", DEF_TRACKMOUSE, t_Bool},
+    {&object,        "object",     "Object",     DEF_OBJECT,     t_Int},
 
 };
 
 static OptionStruct desc[] = {
-    /*{(char *) "-count spheres", (char *) "set number of spheres"},*/
-    /*{(char *) "-cycles speed", (char *) "set ball speed value"},*/
-    {(char *) "-/+texture", (char *) "turn on/off texturing"},
-    {(char *) "-/+trackmouse", (char *) "turn on/off the tracking of the mouse"},
-    {(char *) "-object num", (char *) "number of the 3D object (0 means random)"},
+    /*{"-count spheres", "set number of spheres"},*/
+    /*{"-cycles speed", "set ball speed value"},*/
+    {"-/+texture", "turn on/off texturing"},
+    {"-/+trackmouse", "turn on/off the tracking of the mouse"},
+    {"-object num", "number of the 3D object (0 means random)"},
 };
 
 ModeSpecOpt sballs_opts =
@@ -441,7 +449,10 @@ static void inittextures(ModeInfo * mi)
         clear_gl_error();
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                     sb->btexture->width, sb->btexture->height, 0,
-                    GL_RGBA, GL_UNSIGNED_BYTE, sb->btexture->data);
+                    GL_RGBA,
+                     /* GL_UNSIGNED_BYTE, */
+                     GL_UNSIGNED_INT_8_8_8_8_REV,
+                     sb->btexture->data);
         check_gl_error("texture");
 
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -472,7 +483,10 @@ static void inittextures(ModeInfo * mi)
         clear_gl_error();
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                     sb->ftexture->width, sb->ftexture->height, 0,
-                    GL_RGBA, GL_UNSIGNED_BYTE, sb->ftexture->data);
+                    GL_RGBA,
+                     /* GL_UNSIGNED_BYTE, */
+                     GL_UNSIGNED_INT_8_8_8_8_REV,
+                     sb->ftexture->data);
         check_gl_error("texture");
 
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -501,8 +515,8 @@ static void drawSphere(ModeInfo * mi,int sphere_num)
   float x = polygons[object].v[sphere_num][0];
   float y = polygons[object].v[sphere_num][1];
   float z = polygons[object].v[sphere_num][2];
-  int numMajor = 10;
-  int numMinor = 10;
+  int numMajor = 15;
+  int numMinor = 30;
   float radius = sb->radius[sphere_num];
   double majorStep = (M_PI / numMajor);
   double minorStep = (2.0 * M_PI / numMinor);
@@ -535,6 +549,8 @@ static void drawSphere(ModeInfo * mi,int sphere_num)
       glNormal3f((x * r1) / radius, (y * r1) / radius, z1 / radius);
       glTexCoord2f(j / (GLfloat) numMinor, (i + 1) / (GLfloat) numMajor);
       glVertex3f(x * r1, y * r1, z1);
+
+      mi->polygon_count++;
     }
     glEnd();
   }
@@ -585,6 +601,8 @@ static void Draw(ModeInfo * mi)
     sballsstruct *sb = &sballs[MI_SCREEN(mi)];
     int sphere;
 
+    mi->polygon_count = 0;
+
     if (do_trackmouse && !MI_IS_ICONIC(mi))
        trackmouse(mi);
 
@@ -616,6 +634,7 @@ static void Draw(ModeInfo * mi)
     glNormal3f(0, 0, 1); glTexCoord2f(1,0); glVertex3f(-8, 4.1, -4);
     glNormal3f(0, 0, 1); glTexCoord2f(1,1); glVertex3f(-8, -4.1, -4);
     glEnd();
+    mi->polygon_count++;
 
     /* rotate the mouse */
     glRotatef(sb->rot[0], 1.0f, 0.0f, 0.0f);
@@ -675,10 +694,8 @@ static void Init(ModeInfo * mi)
     sb->speed = MI_CYCLES(mi);
 
     /* initialise object number */
-    if (object == 0)
-       object = NRAND(MAX_OBJ);
     if ((object == 0) || (object > MAX_OBJ))
-       object = DEF_OBJECT_INDX;
+      object = NRAND(MAX_OBJ-1)+1;
     object--;
 
     /* initialise sphere number */
@@ -836,10 +853,8 @@ void change_sballs(ModeInfo * mi)
        return;
 
     /* initialise object number */
-    if (object == 0)
-       object = NRAND(MAX_OBJ);
     if ((object == 0) || (object > MAX_OBJ))
-       object = DEF_OBJECT_INDX;
+      object = NRAND(MAX_OBJ-1)+1;
     object--;
 
     /* correct sphere number */