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 release_lockward 0
45 #define NUMOF(x) (sizeof ((x)) / sizeof ((*x)))
50 #define COLORIDX_SHF 4
54 /***************************************************************************
55 * Structure definitions.
57 struct lockward_context; /* Forward declaration. */
62 #define uint8_t unsigned char
63 #define uint16_t unsigned short
64 #define uint32_t unsigned int
66 typedef struct bladestate {
67 uint8_t outer, inner; /* Radii */
70 typedef struct spinnerstate {
71 GLfloat rot; /* Terminal rotation after count expires */
72 GLfloat rotinc; /* Per-frame increment to rot. */
75 int ncolors; /* n.4 fixed-point */
76 int ccolor; /* n.4 fixed-point */
77 int colorinc; /* n.4 fixed-point */
82 typedef struct blinkstate {
83 int (*drawfunc) (struct lockward_context *ctx,
84 struct blinkstate *bs);
85 uint32_t *noise; /* For draw_blink_segment_scatter() */
88 int16_t dwell; /* <0: sharp >0: decay */
97 BTYPE_RADIAL_SINGLE = 0,
100 BTYPE_RADIAL_DOUBLESEQ,
101 BTYPE_SEGMENT_SINGLE,
102 BTYPE_SEGMENT_RANDOM,
103 BTYPE_CONCENTRIC_SINGLE,
104 BTYPE_CONCENTRIC_RANDOM,
105 BTYPE_CONCENTRIC_SEQ,
106 BTYPE_SEGMENT_SCATTER,
110 typedef struct { GLfloat x,y,z; } XYZ;
112 typedef struct lockward_context {
113 GLXContext *glx_context;
115 spinnerstate spinners[NSPINNERS];
118 /* This used to put vertexes into lists without putting begin/end
119 into the same list! I didn't even know that worked. Well, it
120 doesn't work with jwzgles, so I changed it to not do that. */
121 /* GLuint blades_outer, blades_inner; */
122 XYZ points_outer[NRADII][SUBDIV+1];
123 XYZ points_inner[NRADII][SUBDIV+1];
133 /***************************************************************************
136 ENTRYPOINT void free_lockward (ModeInfo *mi);
139 /***************************************************************************
142 static lockward_context *g_ctx = NULL;
143 static Bool g_blink_p = True;
144 static int g_blades = NBLADES;
145 static int g_rotateidle_min,
147 static int g_blinkidle_min,
149 static int g_blinkdwell_min,
152 #define DEF_BLINK "True"
153 #define DEF_ROTATEIDLEMIN "1000"
154 #define DEF_ROTATEIDLEMAX "6000"
155 #define DEF_BLINKIDLEMIN "1000"
156 #define DEF_BLINKIDLEMAX "9000"
157 #define DEF_BLINKDWELLMIN "100"
158 #define DEF_BLINKDWELLMAX "600"
161 static XrmOptionDescRec opts[] = {
162 { "-blink", ".blink", XrmoptionNoArg, "on" },
163 { "+blink", ".blink", XrmoptionNoArg, "off" },
164 { "-rotateidle-min", ".rotateidlemin", XrmoptionSepArg, 0 },
165 { "-rotateidle-max", ".rotateidlemax", XrmoptionSepArg, 0 },
166 { "-blinkidle-min", ".blinkidlemin", XrmoptionSepArg, 0 },
167 { "-blinkidle-max", ".blinkidlemax", XrmoptionSepArg, 0 },
168 { "-blinkdwell-min", ".blinkdwellmin", XrmoptionSepArg, 0 },
169 { "-blinkdwell-max", ".blinkdwellmax", XrmoptionSepArg, 0 },
172 static argtype vars[] = {
173 { &g_blink_p, "blink", "Blink", DEF_BLINK, t_Bool },
174 { &g_rotateidle_min, "rotateidlemin", "Rotateidlemin", DEF_ROTATEIDLEMIN, t_Int },
175 { &g_rotateidle_max, "rotateidlemax", "Rotateidlemax", DEF_ROTATEIDLEMAX, t_Int },
176 { &g_blinkidle_min, "blinkidlemin", "Blinkidlemin", DEF_BLINKIDLEMIN, t_Int },
177 { &g_blinkidle_max, "blinkidlemax", "Blinkidlemax", DEF_BLINKIDLEMAX, t_Int },
178 { &g_blinkdwell_min, "blinkdwellmin", "Blinkdwellmin", DEF_BLINKDWELLMIN, t_Int },
179 { &g_blinkdwell_max, "blinkdwellmax", "Blinkdwellmax", DEF_BLINKDWELLMAX, t_Int },
182 static OptionStruct desc[] = {
183 { "-/+blink", "Turn on/off blinking effects." },
184 { "-rotateidle-min", "Minimum idle time for rotators, in milliseconds." },
185 { "-rotateidle-max", "Maximum idle time for rotators, in milliseconds." },
186 { "-blinkidle-min", "Minimum idle time between blink effects, in milliseconds." },
187 { "-blinkidle-max", "Maximum idle time between blink effects, in milliseconds." },
188 { "-blinkdwell-min", "Minimum dwell time for blink effects, in milliseconds." },
189 { "-blinkdwell-max", "Maximum dwell time for blink effects, in milliseconds." },
192 ENTRYPOINT ModeSpecOpt lockward_opts = {
193 NUMOF(opts), opts, NUMOF(vars), vars, desc
197 /***************************************************************************
201 reshape_lockward (ModeInfo *mi, int width, int height)
203 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
204 GLfloat h = (GLfloat) height / (GLfloat) width;
207 if (width > height * 5) { /* tiny window: show middle */
208 height = width * 9/16;
210 h = height / (GLfloat) width;
213 glXMakeCurrent (MI_DISPLAY (mi), MI_WINDOW (mi), *ctx->glx_context);
215 glViewport (0, y, (GLint) width, (GLint) height);
217 glMatrixMode (GL_PROJECTION);
220 glOrtho (-8.0, 8.0, -8.0 * h, 8.0 * h, -1, 1);
222 glOrtho (-8.0 / h, 8.0 / h, -8.0, 8.0, -1, 1);
224 glMatrixMode (GL_MODELVIEW);
228 lockward_handle_event (ModeInfo *mi, XEvent *event)
230 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
232 if (event->xany.type == KeyPress) {
236 XLookupString (&event->xkey, &c, 1, &keysym, 0);
237 if (c == ' ' || c == '\t') {
247 /***************************************************************************
251 random_blade_rot (lockward_context *ctx, struct spinnerstate *ss)
254 * The circle is divided up in to g_blades divisions. The idea here
255 * is to rotate to an exact division point.
257 * The target rotation is computed via random numbers.
259 * The time it takes to get there is a maximum of six seconds per
260 * division, and a minimum of one second (no matter how far away it
261 * is), and is selected by random numbers.
263 * The time value is converted into frames, and a per-frame rotation
266 * During rendering, we approach the target rotation by subtracting
267 * from it the per-frame rotation times the number of outstanding
268 * ticks. Doing it this way means we'll hit the target rotation
269 * exactly, without low-order errors creeping in to the values (at
270 * least not nearly as quickly).
275 dist = random() % g_blades + 1;
277 ss->rotcount = random() % (6 * dist * ctx->fps - ctx->fps)
282 d = dist * 360.0 / (GLfloat) g_blades;
284 ss->rotinc = d / (GLfloat) ss->rotcount;
289 * A "blade" is pie-wedge shaped flat thing that is rotated around where the
290 * apex is/would be. Initially envisioned as 1/12th of a circle, but that
291 * could be configurable. The inner and outer edges are rounded off using
292 * six subdivisions so that, when multiple blades are assembled, it looks
293 * more like a circle and less like a polygon.
295 * The blade is assembled as a tri-fan. It is oriented centered at 3
296 * o'clock. The blade is composed of two display lists -- arcs, essentially
297 * -- the outer and the inner one. The outer one *must* be called before
298 * the inner one, or the blade clockwise-ness will be wrong, and become
299 * invisible. Arcs of various radii are compiled.
303 gen_blade_arcs (lockward_context *ctx)
305 GLfloat here, there, step;
309 there = M_PI * 2.0 / g_blades;
310 step = there / SUBDIV;
311 here -= SUBDIV * step / 2.0;
314 * Build outer blade arcs.
315 * Start at left side of outer radius. Strike all its vertices.
317 for (n = 0; n < NRADII; ++n) {
318 /* glNewList (ctx->blades_outer + n, GL_COMPILE); */
319 XYZ *a = ctx->points_outer[n];
321 for (i = SUBDIV; i >= 0; --i) {
322 /* glVertex3f (cos (here + step * i) * (n + 1.0),
323 sin (here + step * i) * (n + 1.0), 0); */
324 a[j].x = cos (here + step * i) * (n + 1.0);
325 a[j].y = sin (here + step * i) * (n + 1.0);
329 if (j != SUBDIV+1) abort();
334 * Build inner blade arcs.
335 * Move to inner radius, strike all vertices in opposite order.
337 for (n = 0; n < NRADII; ++n) {
338 /* glNewList (ctx->blades_inner + n, GL_COMPILE); */
339 XYZ *a = ctx->points_inner[n];
341 for (i = 0; i <= SUBDIV; ++i) {
342 /* glVertex3f (cos (here + step * i) * (n + 1.0),
343 sin (here + step * i) * (n + 1.0), 0); */
344 a[j].x = cos (here + step * i) * (n + 1.0);
345 a[j].y = sin (here + step * i) * (n + 1.0);
349 if (j != SUBDIV+1) abort();
355 gen_rings (lockward_context *ctx)
360 step = M_PI * 2.0 / (g_blades * SUBDIV);
362 for (n = 0; n < NRADII - 1; ++n) {
363 glNewList (ctx->rings + n, GL_COMPILE);
364 glBegin (GL_TRIANGLE_STRIP);
365 for (i = g_blades * SUBDIV; i >= 0; --i) {
366 glVertex3f (cos (step * i) * (n + 1.0),
367 sin (step * i) * (n + 1.0), 0);
368 glVertex3f (cos (step * i) * (n + 2.0),
369 sin (step * i) * (n + 2.0), 0);
377 /***************************************************************************
381 calc_interval_frames (lockward_context *ctx, int min, int max)
384 * Compute random interval between min and max milliseconds.
385 * Returned value is in frames.
391 i += random() % (max - min);
393 return i * ctx->fps / 1000;
397 set_alpha_by_dwell (struct blinkstate *bs)
400 bs->color[3] = (GLfloat) bs->dwellcnt / (GLfloat) bs->dwell;
402 bs->color[3] = bs->dwellcnt > (-bs->dwell >> 2) ? 1.0 : 0.0;
407 draw_blink_blade (lockward_context *ctx, int inner, int outer,
411 if (begin_p) glBegin (GL_TRIANGLE_FAN);
412 /* glCallList (ctx->blades_outer + outer); */
413 for (i = 0; i < countof(*ctx->points_outer); i++)
414 glVertex3f(ctx->points_outer[outer][i].x,
415 ctx->points_outer[outer][i].y,
416 ctx->points_outer[outer][i].z);
418 /* glCallList (ctx->blades_inner + inner); */
419 for (i = 0; i < countof(*ctx->points_inner); i++)
420 glVertex3f(ctx->points_inner[inner][i].x,
421 ctx->points_inner[inner][i].y,
422 ctx->points_inner[inner][i].z);
423 if (begin_p) glEnd();
427 draw_blink_radial_random (lockward_context *ctx, struct blinkstate *bs)
432 * There is no sense of direction in a random sweep, so re-use the
433 * 'direction' field to hold the current blade we're messing with.
435 if (bs->dwellcnt < 0) {
436 if (bs->counter <= 0) {
442 * Find available blade. Potentially very slow, depending on
443 * how unlucky we are.
446 i = random() % g_blades;
447 } while (bs->val & (1 << i));
448 bs->val |= (1 << i); /* Mark as used. */
450 if ((bs->dwellcnt = bs->dwell) < 0)
451 bs->dwellcnt = -bs->dwellcnt;
453 if ( bs->type == BTYPE_SEGMENT_SINGLE
454 || bs->type == BTYPE_SEGMENT_RANDOM)
455 bs->radius = random() % (NRADII - 1);
460 set_alpha_by_dwell (bs);
461 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
462 glColor4fv (bs->color);
463 glRotatef (bs->direction * 360.0 / (GLfloat) g_blades, 0, 0, 1);
465 draw_blink_blade (ctx, bs->radius, bs->radius + 1, True);
467 draw_blink_blade (ctx, 0, NRADII - 1, True);
471 return SUBDIV + SUBDIV;
475 draw_blink_radial_sequential (lockward_context *ctx, struct blinkstate *bs)
477 if (bs->dwellcnt < 0) {
478 if (bs->counter <= 0) {
482 if ((bs->dwellcnt = bs->dwell) < 0)
483 bs->dwellcnt = -bs->dwellcnt;
487 set_alpha_by_dwell (bs);
488 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
489 glColor4fv (bs->color);
490 glRotatef ((bs->counter * bs->direction + (int) bs->val)
491 * 360.0 / (GLfloat) g_blades,
493 draw_blink_blade (ctx, 0, NRADII - 1, True);
497 return SUBDIV + SUBDIV;
501 draw_blink_radial_doubleseq (lockward_context *ctx, struct blinkstate *bs)
505 if (bs->dwellcnt < 0) {
506 if (bs->counter <= 0) {
510 if ((bs->dwellcnt = bs->dwell) < 0)
511 bs->dwellcnt = -bs->dwellcnt;
515 set_alpha_by_dwell (bs);
516 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
517 glColor4fv (bs->color);
520 glRotatef (((int) bs->val + bs->counter) * 360.0 / (GLfloat) g_blades,
522 draw_blink_blade (ctx, 0, NRADII - 1, True);
524 polys = SUBDIV + SUBDIV;
526 if (bs->counter && bs->counter < g_blades / 2) {
527 glRotatef (((int) bs->val - bs->counter)
528 * 360.0 / (GLfloat) g_blades,
530 draw_blink_blade (ctx, 0, NRADII - 1, True);
531 polys += SUBDIV + SUBDIV;
540 draw_blink_concentric_random (lockward_context *ctx, struct blinkstate *bs)
544 if (bs->dwellcnt < 0) {
545 if (bs->counter <= 0) {
551 i = random() % (NRADII - 1);
552 } while (bs->val & (1 << i));
555 if ((bs->dwellcnt = bs->dwell) < 0)
556 bs->dwellcnt = -bs->dwellcnt;
561 set_alpha_by_dwell (bs);
562 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
563 glColor4fv (bs->color);
564 glCallList (ctx->rings + bs->direction);
568 return g_blades * SUBDIV * 2;
572 draw_blink_concentric_sequential (lockward_context *ctx, struct blinkstate *bs)
574 if (bs->dwellcnt < 0) {
575 if (bs->counter <= 0) {
579 if ((bs->dwellcnt = bs->dwell) < 0)
580 bs->dwellcnt = -bs->dwellcnt;
584 set_alpha_by_dwell (bs);
585 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
586 glColor4fv (bs->color);
587 if (bs->direction > 0)
588 glCallList (ctx->rings + (NRADII - 2) - bs->counter);
590 glCallList (ctx->rings + bs->counter);
594 return g_blades * SUBDIV * 2;
598 draw_blink_segment_scatter (lockward_context *ctx, struct blinkstate *bs)
602 if (bs->dwellcnt < 0) {
603 if (bs->counter <= 0) {
609 * Init random noise array. On average, 1/4 of the bits will
610 * be set, which should look nice. (1/2 looks too busy.)
612 for (i = g_blades; --i >= 0; )
613 bs->noise[i] = random() & random()
614 & ((1 << (NRADII - 1)) - 1);
616 if ((bs->dwellcnt = bs->dwell) < 0)
617 bs->dwellcnt = -bs->dwellcnt;
621 set_alpha_by_dwell (bs);
622 glBlendFunc (GL_DST_COLOR, GL_SRC_ALPHA);
623 glColor4fv (bs->color);
625 for (i = g_blades; --i >= 0; ) {
626 register uint32_t bits;
630 * Find consecutive runs of 1 bits. Keep going until we run
633 for (bits = bs->noise[i]; bits; ) {
634 inner = ffs (bits) - 1;
635 bits = ~bits & ~((1 << inner) - 1);
636 outer = ffs (bits) - 1;
637 bits = ~bits & ~((1 << outer) - 1);
640 glRotatef (i * 360.0 / (GLfloat) g_blades, 0, 0, 1);
641 draw_blink_blade (ctx, inner, outer, True);
644 polys += SUBDIV + SUBDIV;
654 random_blink (lockward_context *ctx, struct blinkstate *bs)
662 bs->dwell = calc_interval_frames
663 (ctx, g_blinkdwell_min, g_blinkdwell_max);
665 bs->dwell = -bs->dwell;
667 bs->type = random() % MAX_BTYPE;
670 case BTYPE_RADIAL_SINGLE:
671 case BTYPE_SEGMENT_SINGLE:
672 bs->drawfunc = draw_blink_radial_random;
676 case BTYPE_RADIAL_RANDOM:
677 case BTYPE_SEGMENT_RANDOM:
678 bs->drawfunc = draw_blink_radial_random;
680 bs->counter = g_blades;
682 case BTYPE_RADIAL_SEQ:
683 bs->drawfunc = draw_blink_radial_sequential;
684 bs->val = random() % g_blades; /* Initial offset */
685 bs->direction = random() & 8 ? 1 : -1;
686 bs->counter = g_blades;
688 case BTYPE_RADIAL_DOUBLESEQ:
689 bs->drawfunc = draw_blink_radial_doubleseq;
690 bs->val = random() % g_blades; /* Initial offset */
691 bs->counter = g_blades / 2 + 1;
693 case BTYPE_CONCENTRIC_SINGLE:
694 bs->drawfunc = draw_blink_concentric_random;
698 case BTYPE_CONCENTRIC_RANDOM:
699 bs->drawfunc = draw_blink_concentric_random;
701 bs->counter = NRADII - 1;
703 case BTYPE_CONCENTRIC_SEQ:
704 bs->drawfunc = draw_blink_concentric_sequential;
705 bs->direction = random() & 8 ? 1 : -1;
706 bs->counter = NRADII - 1;
708 case BTYPE_SEGMENT_SCATTER:
709 bs->drawfunc = draw_blink_segment_scatter;
710 bs->counter = random() % (g_blades / 2) + (g_blades / 2) + 1;
716 /***************************************************************************
717 * Main rendering routine.
720 draw_lockward (ModeInfo *mi)
722 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
724 Display *dpy = MI_DISPLAY(mi);
725 Window window = MI_WINDOW(mi);
728 GLfloat scolor[4] = {0.0, 0.0, 0.0, 0.5};
730 if (!ctx->glx_context)
733 glXMakeCurrent (MI_DISPLAY (mi), MI_WINDOW (mi), *ctx->glx_context);
736 glClear (GL_COLOR_BUFFER_BIT);
739 glBlendFunc (GL_ONE, GL_ONE);
741 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
746 mi->polygon_count = 0;
748 for (n = NSPINNERS; --n >= 0; ) {
749 ss = &ctx->spinners[n];
752 i = ss->ccolor >> COLORIDX_SHF;
753 scolor[0] = ss->colors[i].red / 65535.0;
754 scolor[1] = ss->colors[i].green / 65535.0;
755 scolor[2] = ss->colors[i].blue / 65535.0;
759 glRotatef (ss->rot - ss->rotcount * ss->rotinc, 0, 0, 1);
760 for (i = ss->nblades; --i >= 0; ) {
762 glRotatef (360.0 * i / ss->nblades, 0, 0, 1);
764 glBegin (GL_TRIANGLE_FAN);
765 /* glCallList (ctx->blades_outer + ss->bladeidx[i].outer); */
766 /* glCallList (ctx->blades_inner + ss->bladeidx[i].inner); */
767 draw_blink_blade (ctx,
768 ss->bladeidx[i].inner,
769 ss->bladeidx[i].outer,
774 mi->polygon_count += SUBDIV + SUBDIV;
778 /* Advance rotation. */
780 if (ss->rotcount > 0)
783 if (ss->rotinc == 0.0)
784 random_blade_rot (ctx, ss);
786 /* Compute # of ticks to sit idle. */
789 calc_interval_frames (ctx,
795 /* Advance colors. */
796 if ((ss->ccolor += ss->colorinc) >= ss->ncolors)
797 ss->ccolor -= ss->ncolors;
798 else if (ss->ccolor < 0)
799 ss->ccolor += ss->ncolors;
803 if (ctx->blink.drawfunc) {
805 ctx->blink.drawfunc (ctx, &ctx->blink);
807 if (ctx->nextblink > 0)
810 /* Compute # of frames for blink idle time. */
812 calc_interval_frames (ctx,
815 random_blink (ctx, &ctx->blink);
821 if (MI_IS_FPS (mi)) do_fps (mi);
824 glXSwapBuffers (dpy, window);
828 /***************************************************************************
829 * Initialization/teardown.
832 init_lockward (ModeInfo *mi)
834 lockward_context *ctx;
838 ctx = &g_ctx[MI_SCREEN (mi)];
840 ctx->glx_context = init_GL (mi);
842 reshape_lockward (mi, MI_WIDTH (mi), MI_HEIGHT (mi));
844 glEnable (GL_CULL_FACE);
846 glDisable (GL_DEPTH_TEST);
848 glShadeModel (GL_FLAT);
851 /* ctx->blades_outer = glGenLists (NRADII); */
852 /* ctx->blades_inner = glGenLists (NRADII); */
853 ctx->rings = glGenLists (NRADII - 1);
855 /* WTF? ctx->fps = 1000000 / MI_DELAY (mi); */
857 ctx->nextblink = calc_interval_frames
858 (ctx, g_blinkidle_min, g_blinkidle_max);
859 ctx->blink.drawfunc = NULL;
860 ctx->blink.noise = malloc (sizeof (uint32_t) * g_blades);
861 if (!ctx->blink.noise) {
862 fprintf (stderr, "Can't allocate noise array.\n");
866 gen_blade_arcs (ctx);
869 for (i = NSPINNERS; --i >= 0; ) {
870 spinnerstate *ss = &ctx->spinners[i];
875 /* Establish rotation */
876 random_blade_rot (ctx, ss);
879 * Establish color cycling path and rate. Rate avoids zero.
882 ss->colorinc = (random() & ((2 << COLORIDX_SHF) - 1))
883 - (1 << COLORIDX_SHF);
884 if (ss->colorinc >= 0)
887 ss->colors = (XColor *) calloc (ss->ncolors, sizeof (XColor));
890 "Can't allocate XColors for spinner %d.\n",
894 make_smooth_colormap (0, 0, 0,
895 ss->colors, &ss->ncolors,
897 ss->ncolors <<= COLORIDX_SHF;
902 ss->nblades = g_blades;
903 ss->bladeidx = malloc (sizeof (bladestate) * g_blades);
905 fprintf (stderr, "Can't allocate blades.\n");
908 for (n = g_blades; --n >= 0; ) {
910 * Establish blade radii. Can't be equal. Ensure
914 ss->bladeidx[n].outer = random() & 7;
915 ss->bladeidx[n].inner = random() & 7;
916 } while (ss->bladeidx[n].outer ==
917 ss->bladeidx[n].inner);
919 if (ss->bladeidx[n].outer < ss->bladeidx[n].inner) {
922 tmp = ss->bladeidx[n].outer;
923 ss->bladeidx[n].outer = ss->bladeidx[n].inner;
924 ss->bladeidx[n].inner = tmp;
931 free_lockward (ModeInfo *mi)
933 lockward_context *ctx = &g_ctx[MI_SCREEN (mi)];
936 if (!ctx->glx_context) return;
937 glXMakeCurrent (MI_DISPLAY (mi), MI_WINDOW (mi), *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: */