2 * lockward.c: First attempt at an Xscreensaver.
4 * Leo L. Schwab 2007.08.17
6 * Copyright (c) 2007 Leo L. Schwab
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to permit
13 * persons to whom the Software is furnished to do so, subject to the
14 * following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
22 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 * USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include "xlockmore.h"
34 /***************************************************************************
37 #ifdef USE_GL /* whole file */
39 #define DEFAULTS "*delay: 20000 \n"\
42 #define refresh_lockward 0
43 #define release_lockward 0
46 #define NUMOF(x) (sizeof ((x)) / sizeof ((*x)))
51 #define COLORIDX_SHF 4
55 #define countof(x) (sizeof((x))/sizeof((*x)))
58 /***************************************************************************
59 * Structure definitions.
61 struct lockward_context; /* Forward declaration. */
66 #define uint8_t unsigned char
67 #define uint16_t unsigned short
68 #define uint32_t unsigned int
70 typedef struct bladestate {
71 uint8_t outer, inner; /* Radii */
74 typedef struct spinnerstate {
75 GLfloat rot; /* Terminal rotation after count expires */
76 GLfloat rotinc; /* Per-frame increment to rot. */
79 int ncolors; /* n.4 fixed-point */
80 int ccolor; /* n.4 fixed-point */
81 int colorinc; /* n.4 fixed-point */
86 typedef struct blinkstate {
87 int (*drawfunc) (struct lockward_context *ctx,
88 struct blinkstate *bs);
89 uint32_t *noise; /* For draw_blink_segment_scatter() */
92 int16_t dwell; /* <0: sharp >0: decay */
101 BTYPE_RADIAL_SINGLE = 0,
104 BTYPE_RADIAL_DOUBLESEQ,
105 BTYPE_SEGMENT_SINGLE,
106 BTYPE_SEGMENT_RANDOM,
107 BTYPE_CONCENTRIC_SINGLE,
108 BTYPE_CONCENTRIC_RANDOM,
109 BTYPE_CONCENTRIC_SEQ,
110 BTYPE_SEGMENT_SCATTER,
114 typedef struct { GLfloat x,y,z; } XYZ;
116 typedef struct lockward_context {
117 GLXContext *glx_context;
119 spinnerstate spinners[NSPINNERS];
122 /* This used to put vertexes into lists without putting begin/end
123 into the same list! I didn't even know that worked. Well, it
124 doesn't work with jwzgles, so I changed it to not do that. */
125 /* GLuint blades_outer, blades_inner; */
126 XYZ points_outer[NRADII][SUBDIV+1];
127 XYZ points_inner[NRADII][SUBDIV+1];
137 /***************************************************************************
140 static void free_lockward (ModeInfo *mi);
143 /***************************************************************************
146 static lockward_context *g_ctx = NULL;
147 static Bool g_blink_p = True;
148 static int g_blades = NBLADES;
149 static int g_rotateidle_min,
151 static int g_blinkidle_min,
153 static int g_blinkdwell_min,
156 #define DEF_BLINK "True"
157 #define DEF_ROTATEIDLEMIN "1000"
158 #define DEF_ROTATEIDLEMAX "6000"
159 #define DEF_BLINKIDLEMIN "1000"
160 #define DEF_BLINKIDLEMAX "9000"
161 #define DEF_BLINKDWELLMIN "100"
162 #define DEF_BLINKDWELLMAX "600"
165 static XrmOptionDescRec opts[] = {
166 { "-blink", ".blink", XrmoptionNoArg, "on" },
167 { "+blink", ".blink", XrmoptionNoArg, "off" },
168 { "-rotateidle-min", ".rotateidlemin", XrmoptionSepArg, 0 },
169 { "-rotateidle-max", ".rotateidlemax", XrmoptionSepArg, 0 },
170 { "-blinkidle-min", ".blinkidlemin", XrmoptionSepArg, 0 },
171 { "-blinkidle-max", ".blinkidlemax", XrmoptionSepArg, 0 },
172 { "-blinkdwell-min", ".blinkdwellmin", XrmoptionSepArg, 0 },
173 { "-blinkdwell-max", ".blinkdwellmax", XrmoptionSepArg, 0 },
176 static argtype vars[] = {
177 { &g_blink_p, "blink", "Blink", DEF_BLINK, t_Bool },
178 { &g_rotateidle_min, "rotateidlemin", "Rotateidlemin", DEF_ROTATEIDLEMIN, t_Int },
179 { &g_rotateidle_max, "rotateidlemax", "Rotateidlemax", DEF_ROTATEIDLEMAX, t_Int },
180 { &g_blinkidle_min, "blinkidlemin", "Blinkidlemin", DEF_BLINKIDLEMIN, t_Int },
181 { &g_blinkidle_max, "blinkidlemax", "Blinkidlemax", DEF_BLINKIDLEMAX, t_Int },
182 { &g_blinkdwell_min, "blinkdwellmin", "Blinkdwellmin", DEF_BLINKDWELLMIN, t_Int },
183 { &g_blinkdwell_max, "blinkdwellmax", "Blinkdwellmax", DEF_BLINKDWELLMAX, t_Int },
186 static OptionStruct desc[] = {
187 { "-/+blink", "Turn on/off blinking effects." },
188 { "-rotateidle-min", "Minimum idle time for rotators, in milliseconds." },
189 { "-rotateidle-max", "Maximum idle time for rotators, in milliseconds." },
190 { "-blinkidle-min", "Minimum idle time between blink effects, in milliseconds." },
191 { "-blinkidle-max", "Maximum idle time between blink effects, in milliseconds." },
192 { "-blinkdwell-min", "Minimum dwell time for blink effects, in milliseconds." },
193 { "-blinkdwell-max", "Maximum dwell time for blink effects, in milliseconds." },
196 ENTRYPOINT ModeSpecOpt lockward_opts = {
197 NUMOF(opts), opts, NUMOF(vars), vars, desc
201 /***************************************************************************
205 reshape_lockward (ModeInfo *mi, int width, int height)
207 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
208 GLfloat h = (GLfloat) height / (GLfloat) width;
210 glXMakeCurrent (MI_DISPLAY (mi), MI_WINDOW (mi),
211 *(ctx->glx_context));
213 glViewport (0, 0, (GLint) width, (GLint) height);
215 glMatrixMode (GL_PROJECTION);
218 glOrtho (-8.0, 8.0, -8.0 * h, 8.0 * h, -1, 1);
220 glOrtho (-8.0 / h, 8.0 / h, -8.0, 8.0, -1, 1);
222 glMatrixMode (GL_MODELVIEW);
226 lockward_handle_event (ModeInfo *mi, XEvent *event)
228 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
230 if (event->xany.type == KeyPress) {
234 XLookupString (&event->xkey, &c, 1, &keysym, 0);
235 if (c == ' ' || c == '\t') {
245 /***************************************************************************
249 random_blade_rot (lockward_context *ctx, struct spinnerstate *ss)
252 * The circle is divided up in to g_blades divisions. The idea here
253 * is to rotate to an exact division point.
255 * The target rotation is computed via random numbers.
257 * The time it takes to get there is a maximum of six seconds per
258 * division, and a minimum of one second (no matter how far away it
259 * is), and is selected by random numbers.
261 * The time value is converted into frames, and a per-frame rotation
264 * During rendering, we approach the target rotation by subtracting
265 * from it the per-frame rotation times the number of outstanding
266 * ticks. Doing it this way means we'll hit the target rotation
267 * exactly, without low-order errors creeping in to the values (at
268 * least not nearly as quickly).
273 dist = random() % g_blades + 1;
275 ss->rotcount = random() % (6 * dist * ctx->fps - ctx->fps)
280 d = dist * 360.0 / (GLfloat) g_blades;
282 ss->rotinc = d / (GLfloat) ss->rotcount;
287 * A "blade" is pie-wedge shaped flat thing that is rotated around where the
288 * apex is/would be. Initially envisioned as 1/12th of a circle, but that
289 * could be configurable. The inner and outer edges are rounded off using
290 * six subdivisions so that, when multiple blades are assembled, it looks
291 * more like a circle and less like a polygon.
293 * The blade is assembled as a tri-fan. It is oriented centered at 3
294 * o'clock. The blade is composed of two display lists -- arcs, essentially
295 * -- the outer and the inner one. The outer one *must* be called before
296 * the inner one, or the blade clockwise-ness will be wrong, and become
297 * invisible. Arcs of various radii are compiled.
301 gen_blade_arcs (lockward_context *ctx)
303 GLfloat here, there, step;
307 there = M_PI * 2.0 / g_blades;
308 step = there / SUBDIV;
309 here -= SUBDIV * step / 2.0;
312 * Build outer blade arcs.
313 * Start at left side of outer radius. Strike all its vertices.
315 for (n = 0; n < NRADII; ++n) {
316 /* glNewList (ctx->blades_outer + n, GL_COMPILE); */
317 XYZ *a = ctx->points_outer[n];
319 for (i = SUBDIV; i >= 0; --i) {
320 /* glVertex3f (cos (here + step * i) * (n + 1.0),
321 sin (here + step * i) * (n + 1.0), 0); */
322 a[j].x = cos (here + step * i) * (n + 1.0);
323 a[j].y = sin (here + step * i) * (n + 1.0);
327 if (j != SUBDIV+1) abort();
332 * Build inner blade arcs.
333 * Move to inner radius, strike all vertices in opposite order.
335 for (n = 0; n < NRADII; ++n) {
336 /* glNewList (ctx->blades_inner + n, GL_COMPILE); */
337 XYZ *a = ctx->points_inner[n];
339 for (i = 0; i <= SUBDIV; ++i) {
340 /* glVertex3f (cos (here + step * i) * (n + 1.0),
341 sin (here + step * i) * (n + 1.0), 0); */
342 a[j].x = cos (here + step * i) * (n + 1.0);
343 a[j].y = sin (here + step * i) * (n + 1.0);
347 if (j != SUBDIV+1) abort();
353 gen_rings (lockward_context *ctx)
358 step = M_PI * 2.0 / (g_blades * SUBDIV);
360 for (n = 0; n < NRADII - 1; ++n) {
361 glNewList (ctx->rings + n, GL_COMPILE);
362 glBegin (GL_TRIANGLE_STRIP);
363 for (i = g_blades * SUBDIV; i >= 0; --i) {
364 glVertex3f (cos (step * i) * (n + 1.0),
365 sin (step * i) * (n + 1.0), 0);
366 glVertex3f (cos (step * i) * (n + 2.0),
367 sin (step * i) * (n + 2.0), 0);
375 /***************************************************************************
379 calc_interval_frames (lockward_context *ctx, int min, int max)
382 * Compute random interval between min and max milliseconds.
383 * Returned value is in frames.
389 i += random() % (max - min);
391 return i * ctx->fps / 1000;
395 set_alpha_by_dwell (struct blinkstate *bs)
398 bs->color[3] = (GLfloat) bs->dwellcnt / (GLfloat) bs->dwell;
400 bs->color[3] = bs->dwellcnt > (-bs->dwell >> 2) ? 1.0 : 0.0;
405 draw_blink_blade (lockward_context *ctx, int inner, int outer,
409 if (begin_p) glBegin (GL_TRIANGLE_FAN);
410 /* glCallList (ctx->blades_outer + outer); */
411 for (i = 0; i < countof(*ctx->points_outer); i++)
412 glVertex3f(ctx->points_outer[outer][i].x,
413 ctx->points_outer[outer][i].y,
414 ctx->points_outer[outer][i].z);
416 /* glCallList (ctx->blades_inner + inner); */
417 for (i = 0; i < countof(*ctx->points_inner); i++)
418 glVertex3f(ctx->points_inner[inner][i].x,
419 ctx->points_inner[inner][i].y,
420 ctx->points_inner[inner][i].z);
421 if (begin_p) glEnd();
425 draw_blink_radial_random (lockward_context *ctx, struct blinkstate *bs)
430 * There is no sense of direction in a random sweep, so re-use the
431 * 'direction' field to hold the current blade we're messing with.
433 if (bs->dwellcnt < 0) {
434 if (bs->counter <= 0) {
440 * Find available blade. Potentially very slow, depending on
441 * how unlucky we are.
444 i = random() % g_blades;
445 } while (bs->val & (1 << i));
446 bs->val |= (1 << i); /* Mark as used. */
448 if ((bs->dwellcnt = bs->dwell) < 0)
449 bs->dwellcnt = -bs->dwellcnt;
451 if ( bs->type == BTYPE_SEGMENT_SINGLE
452 || bs->type == BTYPE_SEGMENT_RANDOM)
453 bs->radius = random() % (NRADII - 1);
458 set_alpha_by_dwell (bs);
459 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
460 glColor4fv (bs->color);
461 glRotatef (bs->direction * 360.0 / (GLfloat) g_blades, 0, 0, 1);
463 draw_blink_blade (ctx, bs->radius, bs->radius + 1, True);
465 draw_blink_blade (ctx, 0, NRADII - 1, True);
469 return SUBDIV + SUBDIV;
473 draw_blink_radial_sequential (lockward_context *ctx, struct blinkstate *bs)
475 if (bs->dwellcnt < 0) {
476 if (bs->counter <= 0) {
480 if ((bs->dwellcnt = bs->dwell) < 0)
481 bs->dwellcnt = -bs->dwellcnt;
485 set_alpha_by_dwell (bs);
486 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
487 glColor4fv (bs->color);
488 glRotatef ((bs->counter * bs->direction + (int) bs->val)
489 * 360.0 / (GLfloat) g_blades,
491 draw_blink_blade (ctx, 0, NRADII - 1, True);
495 return SUBDIV + SUBDIV;
499 draw_blink_radial_doubleseq (lockward_context *ctx, struct blinkstate *bs)
503 if (bs->dwellcnt < 0) {
504 if (bs->counter <= 0) {
508 if ((bs->dwellcnt = bs->dwell) < 0)
509 bs->dwellcnt = -bs->dwellcnt;
513 set_alpha_by_dwell (bs);
514 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
515 glColor4fv (bs->color);
518 glRotatef (((int) bs->val + bs->counter) * 360.0 / (GLfloat) g_blades,
520 draw_blink_blade (ctx, 0, NRADII - 1, True);
522 polys = SUBDIV + SUBDIV;
524 if (bs->counter && bs->counter < g_blades / 2) {
525 glRotatef (((int) bs->val - bs->counter)
526 * 360.0 / (GLfloat) g_blades,
528 draw_blink_blade (ctx, 0, NRADII - 1, True);
529 polys += SUBDIV + SUBDIV;
538 draw_blink_concentric_random (lockward_context *ctx, struct blinkstate *bs)
542 if (bs->dwellcnt < 0) {
543 if (bs->counter <= 0) {
549 i = random() % (NRADII - 1);
550 } while (bs->val & (1 << i));
553 if ((bs->dwellcnt = bs->dwell) < 0)
554 bs->dwellcnt = -bs->dwellcnt;
559 set_alpha_by_dwell (bs);
560 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
561 glColor4fv (bs->color);
562 glCallList (ctx->rings + bs->direction);
566 return g_blades * SUBDIV * 2;
570 draw_blink_concentric_sequential (lockward_context *ctx, struct blinkstate *bs)
572 if (bs->dwellcnt < 0) {
573 if (bs->counter <= 0) {
577 if ((bs->dwellcnt = bs->dwell) < 0)
578 bs->dwellcnt = -bs->dwellcnt;
582 set_alpha_by_dwell (bs);
583 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
584 glColor4fv (bs->color);
585 if (bs->direction > 0)
586 glCallList (ctx->rings + (NRADII - 2) - bs->counter);
588 glCallList (ctx->rings + bs->counter);
592 return g_blades * SUBDIV * 2;
596 draw_blink_segment_scatter (lockward_context *ctx, struct blinkstate *bs)
600 if (bs->dwellcnt < 0) {
601 if (bs->counter <= 0) {
607 * Init random noise array. On average, 1/4 of the bits will
608 * be set, which should look nice. (1/2 looks too busy.)
610 for (i = g_blades; --i >= 0; )
611 bs->noise[i] = random() & random()
612 & ((1 << (NRADII - 1)) - 1);
614 if ((bs->dwellcnt = bs->dwell) < 0)
615 bs->dwellcnt = -bs->dwellcnt;
619 set_alpha_by_dwell (bs);
620 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
621 glColor4fv (bs->color);
623 for (i = g_blades; --i >= 0; ) {
624 register uint32_t bits;
628 * Find consecutive runs of 1 bits. Keep going until we run
631 for (bits = bs->noise[i]; bits; ) {
632 inner = ffs (bits) - 1;
633 bits = ~bits & ~((1 << inner) - 1);
634 outer = ffs (bits) - 1;
635 bits = ~bits & ~((1 << outer) - 1);
638 glRotatef (i * 360.0 / (GLfloat) g_blades, 0, 0, 1);
639 draw_blink_blade (ctx, inner, outer, True);
642 polys += SUBDIV + SUBDIV;
652 random_blink (lockward_context *ctx, struct blinkstate *bs)
660 bs->dwell = calc_interval_frames
661 (ctx, g_blinkdwell_min, g_blinkdwell_max);
663 bs->dwell = -bs->dwell;
665 bs->type = random() % MAX_BTYPE;
668 case BTYPE_RADIAL_SINGLE:
669 case BTYPE_SEGMENT_SINGLE:
670 bs->drawfunc = draw_blink_radial_random;
674 case BTYPE_RADIAL_RANDOM:
675 case BTYPE_SEGMENT_RANDOM:
676 bs->drawfunc = draw_blink_radial_random;
678 bs->counter = g_blades;
680 case BTYPE_RADIAL_SEQ:
681 bs->drawfunc = draw_blink_radial_sequential;
682 bs->val = random() % g_blades; /* Initial offset */
683 bs->direction = random() & 8 ? 1 : -1;
684 bs->counter = g_blades;
686 case BTYPE_RADIAL_DOUBLESEQ:
687 bs->drawfunc = draw_blink_radial_doubleseq;
688 bs->val = random() % g_blades; /* Initial offset */
689 bs->counter = g_blades / 2 + 1;
691 case BTYPE_CONCENTRIC_SINGLE:
692 bs->drawfunc = draw_blink_concentric_random;
696 case BTYPE_CONCENTRIC_RANDOM:
697 bs->drawfunc = draw_blink_concentric_random;
699 bs->counter = NRADII - 1;
701 case BTYPE_CONCENTRIC_SEQ:
702 bs->drawfunc = draw_blink_concentric_sequential;
703 bs->direction = random() & 8 ? 1 : -1;
704 bs->counter = NRADII - 1;
706 case BTYPE_SEGMENT_SCATTER:
707 bs->drawfunc = draw_blink_segment_scatter;
708 bs->counter = random() % (g_blades / 2) + (g_blades / 2) + 1;
714 /***************************************************************************
715 * Main rendering routine.
718 draw_lockward (ModeInfo *mi)
720 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
722 Display *dpy = MI_DISPLAY(mi);
723 Window window = MI_WINDOW(mi);
726 GLfloat scolor[4] = {0.0, 0.0, 0.0, 0.5};
728 if (!ctx->glx_context)
731 glXMakeCurrent (MI_DISPLAY (mi), MI_WINDOW (mi), *(ctx->glx_context));
734 glClear (GL_COLOR_BUFFER_BIT);
737 glBlendFunc (GL_ONE, GL_ONE);
739 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
744 mi->polygon_count = 0;
746 for (n = NSPINNERS; --n >= 0; ) {
747 ss = &ctx->spinners[n];
750 i = ss->ccolor >> COLORIDX_SHF;
751 scolor[0] = ss->colors[i].red / 65535.0;
752 scolor[1] = ss->colors[i].green / 65535.0;
753 scolor[2] = ss->colors[i].blue / 65535.0;
757 glRotatef (ss->rot - ss->rotcount * ss->rotinc, 0, 0, 1);
758 for (i = ss->nblades; --i >= 0; ) {
760 glRotatef (360.0 * i / ss->nblades, 0, 0, 1);
762 glBegin (GL_TRIANGLE_FAN);
763 /* glCallList (ctx->blades_outer + ss->bladeidx[i].outer); */
764 /* glCallList (ctx->blades_inner + ss->bladeidx[i].inner); */
765 draw_blink_blade (ctx,
766 ss->bladeidx[i].inner,
767 ss->bladeidx[i].outer,
772 mi->polygon_count += SUBDIV + SUBDIV;
776 /* Advance rotation. */
778 if (ss->rotcount > 0)
781 if (ss->rotinc == 0.0)
782 random_blade_rot (ctx, ss);
784 /* Compute # of ticks to sit idle. */
787 calc_interval_frames (ctx,
793 /* Advance colors. */
794 if ((ss->ccolor += ss->colorinc) >= ss->ncolors)
795 ss->ccolor -= ss->ncolors;
796 else if (ss->ccolor < 0)
797 ss->ccolor += ss->ncolors;
801 if (ctx->blink.drawfunc) {
803 ctx->blink.drawfunc (ctx, &ctx->blink);
805 if (ctx->nextblink > 0)
808 /* Compute # of frames for blink idle time. */
810 calc_interval_frames (ctx,
813 random_blink (ctx, &ctx->blink);
819 if (MI_IS_FPS (mi)) do_fps (mi);
822 glXSwapBuffers (dpy, window);
826 /***************************************************************************
827 * Initialization/teardown.
830 init_lockward (ModeInfo *mi)
832 lockward_context *ctx;
835 MI_INIT (mi, g_ctx, free_lockward);
836 ctx = &g_ctx[MI_SCREEN (mi)];
838 ctx->glx_context = init_GL (mi);
840 reshape_lockward (mi, MI_WIDTH (mi), MI_HEIGHT (mi));
842 glEnable (GL_CULL_FACE);
844 glDisable (GL_DEPTH_TEST);
846 glShadeModel (GL_FLAT);
849 /* ctx->blades_outer = glGenLists (NRADII); */
850 /* ctx->blades_inner = glGenLists (NRADII); */
851 ctx->rings = glGenLists (NRADII - 1);
853 ctx->fps = 1000000 / MI_DELAY (mi);
854 ctx->nextblink = calc_interval_frames
855 (ctx, g_blinkidle_min, g_blinkidle_max);
856 ctx->blink.drawfunc = NULL;
857 ctx->blink.noise = malloc (sizeof (uint32_t) * g_blades);
858 if (!ctx->blink.noise) {
859 fprintf (stderr, "Can't allocate noise array.\n");
863 gen_blade_arcs (ctx);
866 for (i = NSPINNERS; --i >= 0; ) {
867 spinnerstate *ss = &ctx->spinners[i];
872 /* Establish rotation */
873 random_blade_rot (ctx, ss);
876 * Establish color cycling path and rate. Rate avoids zero.
879 ss->colorinc = (random() & ((2 << COLORIDX_SHF) - 1))
880 - (1 << COLORIDX_SHF);
881 if (ss->colorinc >= 0)
884 ss->colors = (XColor *) calloc (ss->ncolors, sizeof (XColor));
887 "Can't allocate XColors for spinner %d.\n",
891 make_smooth_colormap (0, 0, 0,
892 ss->colors, &ss->ncolors,
894 ss->ncolors <<= COLORIDX_SHF;
899 ss->nblades = g_blades;
900 ss->bladeidx = malloc (sizeof (bladestate) * g_blades);
902 fprintf (stderr, "Can't allocate blades.\n");
905 for (n = g_blades; --n >= 0; ) {
907 * Establish blade radii. Can't be equal. Ensure
911 ss->bladeidx[n].outer = random() & 7;
912 ss->bladeidx[n].inner = random() & 7;
913 } while (ss->bladeidx[n].outer ==
914 ss->bladeidx[n].inner);
916 if (ss->bladeidx[n].outer < ss->bladeidx[n].inner) {
919 tmp = ss->bladeidx[n].outer;
920 ss->bladeidx[n].outer = ss->bladeidx[n].inner;
921 ss->bladeidx[n].inner = tmp;
928 free_lockward (ModeInfo *mi)
930 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
933 if (!ctx->glx_context)
936 glXMakeCurrent (MI_DISPLAY (mi), MI_WINDOW (mi),
937 *(ctx->glx_context));
939 if (ctx->blink.noise)
940 free (ctx->blink.noise);
941 if (glIsList (ctx->rings))
942 glDeleteLists (ctx->rings, NRADII - 1);
943 /* if (glIsList (ctx->blades_outer))
944 glDeleteLists (ctx->blades_outer, NRADII);
945 if (glIsList (ctx->blades_inner))
946 glDeleteLists (ctx->blades_inner, NRADII); */
948 for (i = NSPINNERS; --i >= 0; ) {
949 spinnerstate *ss = &ctx->spinners[i];
959 XSCREENSAVER_MODULE ("Lockward", lockward)
963 /* vim:se ts=8 sts=8 sw=8: */