From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / pulsar.c
index 986f284634fbbc6119bec7eb4a870c53ed84a76b..869933b6e24a4c89e11935b5d062eaf87187a4fa 100644 (file)
@@ -44,8 +44,8 @@
 #define        DEFAULTS                        "*delay:                        10000   \n" \
                                                                                "*showFPS:          False   \n" \
 
-# define refresh_pulsar 0
-# define pulsar_handle_event 0
+# define release_pulsar 0
+# define pulsar_handle_event xlockmore_no_events
 # include "xlockmore.h"                                /* from the xpulsar distribution */
 #else /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
@@ -77,7 +77,7 @@
 #define HEIGHT 600
 
 #define NUM_QUADS 5
-#define DEF_NUM_QUADS  "5"
+#define DEF_QUADS      "5"
 #define DEF_LIGHT              "False"
 #define DEF_WIRE               "False"
 #define DEF_BLEND      "True"
@@ -116,8 +116,8 @@ static XrmOptionDescRec opts[] = {
   {"+antialias",   ".pulsar.antialias",   XrmoptionNoArg, "false" },
   {"-texture",   ".pulsar.texture",   XrmoptionNoArg, "true" },
   {"+texture",   ".pulsar.texture",   XrmoptionNoArg, "false" },
-  {"-texture_quality",   ".pulsar.texture_quality",   XrmoptionNoArg, "true" },
-  {"+texture_quality",   ".pulsar.texture_quality",   XrmoptionNoArg, "false" },
+  {"-texture_quality",   ".pulsar.textureQuality",   XrmoptionNoArg, "true" },
+  {"+texture_quality",   ".pulsar.textureQuality",   XrmoptionNoArg, "false" },
   {"-mipmap",   ".pulsar.mipmap",   XrmoptionNoArg, "true" },
   {"+mipmap",   ".pulsar.mipmap",   XrmoptionNoArg, "false" },
   {"-do_depth",   ".pulsar.doDepth",   XrmoptionNoArg, "true" },
@@ -127,14 +127,14 @@ static XrmOptionDescRec opts[] = {
 
 
 static argtype vars[] = {
-  {&num_quads,    "quads",     "Quads",     DEF_NUM_QUADS, t_Int},
+  {&num_quads,    "quads",     "Quads",     DEF_QUADS,     t_Int},
   {&do_light,     "light",     "Light",     DEF_LIGHT,     t_Bool},
   {&do_wire,      "wire",      "Wire",      DEF_WIRE,      t_Bool},
   {&do_blend,     "blend",     "Blend",     DEF_BLEND,     t_Bool},
   {&do_fog,       "fog",       "Fog",       DEF_FOG,       t_Bool},
   {&do_antialias, "antialias", "Antialias", DEF_ANTIALIAS, t_Bool},
   {&do_texture,   "texture",   "Texture",   DEF_TEXTURE,   t_Bool},
-  {&do_texture_quality, "texture_quality", "Texture_quality", DEF_TEXTURE_QUALITY,   t_Bool},
+  {&do_texture_quality, "textureQuality", "TextureQuality", DEF_TEXTURE_QUALITY,   t_Bool},
   {&do_mipmap,    "mipmap",    "Mipmap",    DEF_MIPMAP,    t_Bool},
   {&do_depth,    "doDepth",    "DoDepth",   DEF_DO_DEPTH,  t_Bool},
   {&which_image, "image",      "Image",     DEF_IMAGE,     t_String},
@@ -160,8 +160,8 @@ ENTRYPOINT ModeSpecOpt pulsar_opts = {countof(opts), opts, countof(vars), vars,
 
 #ifdef USE_MODULES
 ModStruct   pulsar_description =
-{"pulsar", "init_pulsar", "draw_pulsar", "release_pulsar",
- "draw_pulsar", "init_pulsar", NULL, &pulsar_opts,
+{"pulsar", "init_pulsar", "draw_pulsar", NULL,
+ "draw_pulsar", "init_pulsar", "free_pulsar", &pulsar_opts,
  1000, 1, 2, 1, 4, 1.0, "",
  "OpenGL pulsar", 0, NULL};
 #endif
@@ -230,11 +230,16 @@ static void Create_Texture(ModeInfo *mi, const char *filename)
   int format;
 
   if ( !strncmp(filename, "BUILTIN", 7))
-    image = Generate_Image(&width, &height, &format);
+    {
+    BUILTIN:
+      image = Generate_Image(&width, &height, &format);
+    }
   else
     {
       XImage *ximage = xpm_file_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi),
                                            MI_COLORMAP (mi), filename);
+      if (! ximage)
+        goto BUILTIN;
       image  = (GLubyte *) ximage->data;
       width  = ximage->width;
       height = ximage->height;
@@ -363,6 +368,10 @@ static void initializeGL(ModeInfo *mi, GLsizei width, GLsizei height)
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
   }
 
+# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
+  do_wire = 0;
+# endif
+
   if (do_wire)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
   else 
@@ -435,6 +444,7 @@ static GLvoid drawScene(ModeInfo * mi)
   /* use XYZ scaling factors to change the size of the pulsar */
   glScalef(gp->scale_x, gp->scale_y, gp->scale_z);
   drawQuads(gp);
+  mi->polygon_count = num_quads;
 
   /* update the scaling factors- cyclic */
   gp->scale_x = cos(gp->frame/360.)*10.;
@@ -478,10 +488,7 @@ init_pulsar(ModeInfo * mi)
 
   pulsarstruct *gp;
 
-  if (Pulsar == NULL) {
-       if ((Pulsar = (pulsarstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (pulsarstruct))) == NULL)
-         return;
-  }
+  MI_INIT (mi, Pulsar);
   gp = &Pulsar[screen];
 
   gp->window = MI_WINDOW(mi);
@@ -498,18 +505,10 @@ init_pulsar(ModeInfo * mi)
 
 
 /* all sorts of nice cleanup code should go here! */
-ENTRYPOINT void release_pulsar(ModeInfo * mi)
+ENTRYPOINT void free_pulsar(ModeInfo * mi)
 {
-  int screen;
-  if (Pulsar != NULL) {
-       for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-         pulsarstruct *gp = &Pulsar[screen];
-      free(gp->quads);
-       }
-       (void) free((void *) Pulsar);
-       Pulsar = NULL;
-  }
-  FreeAllGL(mi);
+  pulsarstruct *gp = &Pulsar[MI_SCREEN(mi)];
+  free(gp->quads);
 }
 #endif