X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fatlantis.c;h=98ebf3235f9800c37feb4cde205876e44d40cc68;hb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;hp=e0a90ae897fe630734516ced4e9addf4668d8aa1;hpb=96a411663168b0ba5432b407a83be55f3df0c802;p=xscreensaver diff --git a/hacks/glx/atlantis.c b/hacks/glx/atlantis.c index e0a90ae8..98ebf323 100644 --- a/hacks/glx/atlantis.c +++ b/hacks/glx/atlantis.c @@ -29,7 +29,7 @@ static const char sccsid[] = "@(#)atlantis.c 5.08 2003/04/09 xlockmore"; * Thanks goes also to Brian Paul for making it possible and inexpensive * to use OpenGL at home. * - * My e-mail address is lassauge@mail.dotcom.fr + * My e-mail address is lassauge@users.sourceforge.net * * Eric Lassauge (May-13-1998) * @@ -57,7 +57,6 @@ static const char sccsid[] = "@(#)atlantis.c 5.08 2003/04/09 xlockmore"; * Add support for -/+ wireframe (t'was so easy to do!) * * TODO : - * - add a sort of background image or random bg color * - better handling of sizes and speeds * - test standalone and module modes * - purify it (!) @@ -103,34 +102,26 @@ static const char sccsid[] = "@(#)atlantis.c 5.08 2003/04/09 xlockmore"; */ #define DEF_TEXTURE "True" -#define DEF_GRADIENT "False" +#define DEF_GRADIENT "True" #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: 25000 \n" \ "*count: 4 \n" \ "*showFPS: False \n" \ "*cycles: 100 \n" \ "*size: 6000 \n" \ - "*wireframe: False \n" \ - "*texture: " DEF_TEXTURE " \n" \ - "*gradient: " DEF_GRADIENT " \n" \ - "*whalespeed: " DEF_WHALESPEED " \n" + "*wireframe: False \n" +# define atlantis_handle_event 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ -#include "vis.h" +# include "vis.h" #endif /* !STANDALONE */ #ifdef USE_GL #include "atlantis.h" -#include static int whalespeed; @@ -138,27 +129,28 @@ 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"}, + {"-whalespeed", ".atlantis.whalespeed", XrmoptionSepArg, 0}, + {"-texture", ".atlantis.texture", XrmoptionNoArg, "true"}, + {"+texture", ".atlantis.texture", XrmoptionNoArg, "false"}, + {"-gradient", ".atlantis.gradient", XrmoptionNoArg, "true"}, + {"+gradient", ".atlantis.gradient", XrmoptionNoArg, "false"}, }; static argtype vars[] = { - {(caddr_t *) & whalespeed, "whalespeed", "WhaleSpeed", DEF_WHALESPEED, t_Int}, - {(caddr_t *) &do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool}, - {(caddr_t *) &do_gradient, "gradient", "Gradient", DEF_GRADIENT, 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[] = { {"-whalespeed num", "speed of whales and the dolphin"}, - {"-texture num", "whether to introduce water-like distortion"} + {"-texture", "whether to introduce water-like distortion"}, + {"-gradient", "whether to introduce gradient-filled background"}, }; -ModeSpecOpt atlantis_opts = +ENTRYPOINT ModeSpecOpt atlantis_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; #ifdef USE_MODULES @@ -230,24 +222,16 @@ Init(ModeInfo *mi) { atlantisstruct *ap = &atlantis[MI_SCREEN(mi)]; - static float ambient[] = - {0.1, 0.1, 0.1, 1.0}; - static float diffuse[] = - {1.0, 1.0, 1.0, 1.0}; - static float position[] = - {0.0, 1.0, 0.0, 0.0}; - static float mat_shininess[] = - {90.0}; - static float mat_specular[] = - {0.8, 0.8, 0.8, 1.0}; - static float mat_diffuse[] = - {0.46, 0.66, 0.795, 1.0}; - static float mat_ambient[] = - {0.0, 0.1, 0.2, 1.0}; - static float lmodel_ambient[] = - {0.4, 0.4, 0.4, 1.0}; - static float lmodel_localviewer[] = - {0.0}; + static const float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static const float diffuse[] = {1.0, 1.0, 1.0, 1.0}; + static const float position[] = {0.0, 1.0, 0.0, 0.0}; + static const float mat_shininess[] = {90.0}; + static const float mat_specular[] = {0.8, 0.8, 0.8, 1.0}; + static const float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0}; + static const float mat_ambient[] = {0.0, 0.1, 0.2, 1.0}; + static const float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0}; + static const float lmodel_localviewer[] = {0.0}; + float fblue = 0.0, fgreen; glFrontFace(GL_CCW); @@ -287,8 +271,6 @@ Init(ModeInfo *mi) } else { - GLfloat s_plane[] = { 1, 0, 0, 0 }; - GLfloat t_plane[] = { 0, 0, 1, 0 }; GLfloat scale = 0.0005; if (!ap->texture) @@ -308,13 +290,18 @@ Init(ModeInfo *mi) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(GL_S, GL_EYE_PLANE, s_plane); - glTexGenfv(GL_T, GL_EYE_PLANE, t_plane); - - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); +# ifndef HAVE_JWZGLES + { + GLfloat s_plane[] = { 1, 0, 0, 0 }; + GLfloat t_plane[] = { 0, 0, 1, 0 }; + glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGenfv(GL_S, GL_EYE_PLANE, s_plane); + glTexGenfv(GL_T, GL_EYE_PLANE, t_plane); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } +# endif glEnable(GL_TEXTURE_2D); glMatrixMode(GL_TEXTURE); @@ -328,10 +315,10 @@ Init(ModeInfo *mi) /* Add a little randomness */ fblue = ((float) (NRAND(30)) / 100.0) + 0.70; fgreen = fblue * 0.56; - glClearColor(0.0, fgreen, fblue, 0.0); + glClearColor(0.0, fgreen, fblue, 1.0); } -void +ENTRYPOINT void reshape_atlantis(ModeInfo * mi, int width, int height) { atlantisstruct *ap = &atlantis[MI_SCREEN(mi)]; @@ -345,16 +332,9 @@ reshape_atlantis(ModeInfo * mi, int width, int height) } -/* jwz -- this doesn't really work very well. - - All I want to do is give the tank a gradient-filled background, instead - of just solid blue. The following was my guess as to how to do this, - but it kills my frame rate. I guess there's a more efficient way to do - this, but I don't see it... - - I mean, all I want to do is dump some non-projected bytes into the color - buffer, then zero out the depth buffer. That *can't* be expensive, can - it? +/* Fill the background with a gradient -- thanks to + Phil Carrig for figuring out + how to do this more efficiently! */ static void clear_tank (atlantisstruct * ap) @@ -363,83 +343,37 @@ clear_tank (atlantisstruct * ap) if (do_gradient && !ap->wire) { - static GLuint gradient_list = 0; - static GLuint gradient_tex = 0; - - if (gradient_list == 0) + GLfloat top[4] = { 0.00, 0.40, 0.70, }; + GLfloat bot[4] = { 0.00, 0.05, 0.18, }; + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + { + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); { - unsigned char *pixels = 0; - int start = 64; - int end = start + 128; - int size = 4 * (end - start); - int i; - - pixels = (unsigned char *) malloc (size); - i = 0; - while (i < size) - { - pixels[i] = 0; i++; - pixels[i] = (start + (i>>2)) * 0.56; i++; - pixels[i] = (start + (i>>2)); i++; - pixels[i] = 255; i++; - } - - clear_gl_error(); - - glGenTextures(1, &gradient_tex); - glBindTexture(GL_TEXTURE_1D, gradient_tex); - - glTexImage1D(GL_TEXTURE_1D, 0, 4, - (end - start), 0, - GL_RGBA, GL_UNSIGNED_BYTE, pixels); - check_gl_error ("gradient texture"); - glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - - gradient_list = glGenLists(1); - glNewList(gradient_list, GL_COMPILE); - - glDepthMask (False); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_1D); - glBindTexture(GL_TEXTURE_1D, gradient_tex); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); glLoadIdentity(); - glRotatef(90, 0, 0, 1); - glTranslatef(-1, -1, 0); - glScalef(2, 2, 1); - - glBegin(GL_QUADS); - glTexCoord1i(1); glVertex3i(1, 0, 0); - glTexCoord1i(0); glVertex3i(0, 0, 0); - glTexCoord1i(0); glVertex3i(0, 1, 0); - glTexCoord1i(1); glVertex3i(1, 1, 0); + glRotatef(current_device_rotation(), 0, 0, 1); + +# ifndef HAVE_JWZGLES + glShadeModel (GL_SMOOTH); +# endif + glDisable (GL_LIGHTING); + glBegin (GL_QUADS); + glColor3fv (bot); + glVertex3f (-1, -1, 1); glVertex3f ( 1, -1, 1); + glColor3fv (top); + glVertex3f ( 1, 1, 1); glVertex3f (-1, 1, 1); glEnd(); - - glPopMatrix(); - - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glDisable(GL_TEXTURE_1D); - - glDepthMask (True); - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - if (do_texture) - glEnable(GL_TEXTURE_2D); - - glEndList(); - check_gl_error ("gradient list"); + glEnable (GL_LIGHTING); } + glPopMatrix(); + } + glMatrixMode(GL_PROJECTION); + glPopMatrix(); - glCallList(gradient_list); + glMatrixMode(GL_MODELVIEW); } } @@ -506,7 +440,7 @@ AllDisplay(atlantisstruct * ap) *----------------------------------------------------------------------------- */ -void +ENTRYPOINT void init_atlantis(ModeInfo * mi) { int screen = MI_SCREEN(mi); @@ -566,7 +500,7 @@ init_atlantis(ModeInfo * mi) * Called by the mainline code periodically to update the display. *----------------------------------------------------------------------------- */ -void +ENTRYPOINT void draw_atlantis(ModeInfo * mi) { atlantisstruct *ap = &atlantis[MI_SCREEN(mi)]; @@ -583,8 +517,11 @@ draw_atlantis(ModeInfo * mi) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + glRotatef(current_device_rotation(), 0, 0, 1); AllDisplay(ap); Animate(ap); + glPopMatrix(); if (mi->fps_p) do_fps (mi); glXSwapBuffers(display, window); @@ -599,9 +536,10 @@ draw_atlantis(ModeInfo * mi) *----------------------------------------------------------------------------- */ -void +ENTRYPOINT void release_atlantis(ModeInfo * mi) { +#if 0 int screen; if (atlantis != NULL) { @@ -615,14 +553,16 @@ release_atlantis(ModeInfo * mi) atlantis = NULL; } FreeAllGL(mi); +#endif } -void +ENTRYPOINT void refresh_atlantis(ModeInfo * mi) { } -void +#ifndef STANDALONE +ENTRYPOINT void change_atlantis(ModeInfo * mi) { atlantisstruct *ap = &atlantis[MI_SCREEN(mi)]; @@ -633,5 +573,8 @@ change_atlantis(ModeInfo * mi) glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(ap->glx_context)); Init(mi); } +#endif /* !STANDALONE */ + +XSCREENSAVER_MODULE ("Atlantis", atlantis) #endif /* USE_GL */