ftp://ftp.jp.xemacs.org/pub/NetBSD/packages/distfiles/xscreensaver-4.15.tar.gz
[xscreensaver] / hacks / glx / atlantis.c
index f1844a5b212abb7b30c20288578c297a4fdb8abf..9e4a449d7052d883cf1c371e6414c61cfcf1963e 100644 (file)
@@ -1,8 +1,7 @@
 /* atlantis --- Shows moving 3D sea animals */
 
-#if !defined( lint ) && !defined( SABER )
-static const char sccsid[] = "@(#)atlantis.c   1.3 98/06/18 xlockmore";
-
+#if 0
+static const char sccsid[] = "@(#)atlantis.c   5.08 2003/04/09 xlockmore";
 #endif
 
 /* Copyright (c) E. Lassauge, 1998. */
@@ -30,7 +29,7 @@ static const char sccsid[] = "@(#)atlantis.c  1.3 98/06/18 xlockmore";
  * Thanks goes also to Brian Paul for making it possible and inexpensive
  * to use OpenGL at home.
  *
- * My e-mail address is lassauge@sagem.fr
+ * My e-mail address is lassauge@mail.dotcom.fr
  *
  * Eric Lassauge  (May-13-1998)
  *
@@ -103,19 +102,25 @@ static const char sccsid[] = "@(#)atlantis.c      1.3 98/06/18 xlockmore";
  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  */
 
+#define DEF_TEXTURE "True"
+#define DEF_GRADIENT "False"
+#define DEF_WHALESPEED  "250"
+
 #ifdef STANDALONE
 # define PROGCLASS     "Atlantis"
 # define HACK_INIT     init_atlantis
 # define HACK_DRAW     draw_atlantis
 # define HACK_RESHAPE  reshape_atlantis
 # define atlantis_opts xlockmore_opts
-# define DEFAULTS      "*delay:       40000 \n" \
+# define DEFAULTS      "*delay:       25000 \n" \
                         "*count:          4 \n" \
                         "*showFPS:    False \n" \
                         "*cycles:       100 \n" \
                         "*size:        6000 \n" \
                         "*wireframe:  False \n" \
-                        "*whalespeed:   250 \n"
+                        "*texture:    " DEF_TEXTURE    " \n" \
+                        "*gradient:   " DEF_GRADIENT   " \n" \
+                        "*whalespeed: " DEF_WHALESPEED " \n"
 # include "xlockmore.h"                /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
 # include "xlock.h"            /* from the xlockmore distribution */
@@ -128,22 +133,23 @@ static const char sccsid[] = "@(#)atlantis.c      1.3 98/06/18 xlockmore";
 #include <GL/glu.h>
 
 
-#define DEF_TEXTURE "True"
-
-#define DEF_WHALESPEED  "250"
 static int  whalespeed;
 static int do_texture;
+static int do_gradient;
 static XrmOptionDescRec opts[] =
 {
      {"-whalespeed", ".atlantis.whalespeed", XrmoptionSepArg, (caddr_t) NULL},
      {"-texture",    ".atlantis.texture",    XrmoptionNoArg, (caddr_t)"true"},
      {"+texture",    ".atlantis.texture",    XrmoptionNoArg, (caddr_t)"false"},
+     {"-gradient",   ".atlantis.gradient",   XrmoptionNoArg, (caddr_t)"true"},
+     {"+gradient",   ".atlantis.gradient",   XrmoptionNoArg, (caddr_t)"false"},
 };
 
 static argtype vars[] =
 {
- {(caddr_t *) & whalespeed, "whalespeed", "WhaleSpeed", DEF_WHALESPEED, t_Int},
- {(caddr_t *) &do_texture,  "texture",    "Texture",    DEF_TEXTURE,   t_Bool},
+ {&whalespeed, "whalespeed", "WhaleSpeed", DEF_WHALESPEED, t_Int},
+ {&do_texture,  "texture",    "Texture",    DEF_TEXTURE,   t_Bool},
+ {&do_gradient, "gradient",   "Gradient",   DEF_GRADIENT,  t_Bool},
 };
 
 static OptionStruct desc[] =
@@ -167,8 +173,10 @@ ModStruct   atlantis_description =
 static atlantisstruct *atlantis = NULL;
 
 #include "xpm-ximage.h"
+
 #include "../images/sea-texture.xpm"
 
+
 static void
 parse_image_data(ModeInfo *mi)
 {
@@ -192,7 +200,7 @@ InitFishs(atlantisstruct * ap)
                ap->sharks[i].v = 1.0;
        }
 
-       /* Random whae direction */
+       /* Random whale direction */
        ap->whaledir = LRAND() & 1;
 
        ap->dolph.x = 30000.0;
@@ -240,7 +248,7 @@ Init(ModeInfo *mi)
        {0.4, 0.4, 0.4, 1.0};
        static float lmodel_localviewer[] =
        {0.0};
-       float       fblue = 0.0, fgreen;
+       float        fblue = 0.0, fgreen;
 
        glFrontFace(GL_CCW);
 
@@ -318,7 +326,7 @@ Init(ModeInfo *mi)
        InitFishs(ap);
 
        /* Add a little randomness */
-       fblue = ((float) (NRAND(50)) / 100.0) + 0.50;
+       fblue = ((float) (NRAND(30)) / 100.0) + 0.70;
        fgreen = fblue * 0.56;
        glClearColor(0.0, fgreen, fblue, 0.0);
 }
@@ -336,6 +344,60 @@ reshape_atlantis(ModeInfo * mi, int width, int height)
        glMatrixMode(GL_MODELVIEW);
 }
 
+
+/* Fill the background with a gradient -- thanks to 
+   Phil Carrig <pod@internode.on.net> for figuring out
+   how to do this more efficiently!
+ */
+static void
+clear_tank (atlantisstruct * ap)
+{
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+  if (do_gradient && !ap->wire)
+    {
+      GLfloat top[3] = { 0.00, 0.40, 0.70 };
+      GLfloat bot[3] = { 0.00, 0.05, 0.18 };
+
+      glMatrixMode(GL_PROJECTION);
+      glPushMatrix();
+      {
+        glLoadIdentity();
+        glMatrixMode(GL_MODELVIEW);
+        glPushMatrix();
+        {
+          glLoadIdentity();
+
+          /* save GL_COLOR_MATERIAL, GL_COLOR_MATERIAL_FACE, etc.
+             This stalls the pipeline, so it would be better to do this
+             with explicit enable/disable calls, but I can't figure
+             out how to undo the glEnable() and glColor() calls below!
+             Simply calling glDisable(GL_COLOR_MATERIAL) is insufficient!
+           */
+          glPushAttrib (GL_LIGHTING_BIT);
+          {
+            glEnable (GL_COLOR_MATERIAL);
+
+            glShadeModel(GL_SMOOTH);
+            glBegin(GL_QUADS);
+            glColor3f (bot[0], bot[1], bot[2]); glVertex3f (-1, -1, 1);
+            glColor3f (bot[0], bot[1], bot[2]); glVertex3f ( 1, -1, 1);
+            glColor3f (top[0], top[1], top[2]); glVertex3f ( 1,  1, 1);
+            glColor3f (top[0], top[1], top[2]); glVertex3f (-1,  1, 1);
+            glEnd();
+          }
+          glPopAttrib();
+        }
+        glPopMatrix();
+      }
+      glMatrixMode(GL_PROJECTION);
+      glPopMatrix();
+
+      glMatrixMode(GL_MODELVIEW);
+    }
+}
+
+
 static void
 Animate(atlantisstruct * ap)
 {
@@ -358,7 +420,7 @@ AllDisplay(atlantisstruct * ap)
 {
        int         i;
 
-       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+        clear_tank(ap);
 
        for (i = 0; i < ap->num_sharks; i++) {
                glPushMatrix();