http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.03.tar.gz
[xscreensaver] / hacks / glx / extrusion.c
1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* extrusion --- extrusion module for xscreensaver */
3 /*-
4  * Permission to use, copy, modify, and distribute this software and its
5  * documentation for any purpose and without fee is hereby granted,
6  * provided that the above copyright notice appear in all copies and that
7  * both that copyright notice and this permission notice appear in
8  * supporting documentation.
9  *
10  * This file is provided AS IS with no warranties of any kind.  The author
11  * shall have no liability with respect to the infringement of copyrights,
12  * trade secrets or any patents by this file or any part thereof.  In no
13  * event will the author be liable for any lost revenue or profits or
14  * other special, indirect and consequential damages.
15
16  * Revision History:
17  * Tue Oct 19 22:24:47 PDT 1999    Initial creation by David Konerding
18  *                                 <dek@cgl.ucsf.edu>
19  *                                                                 
20  * Notes:
21  * This screensaver requires the GLE ("OpenGL Tubing and Extrusion Library")
22  * which can be obtained from http://www.linas.org/gle/index.html
23   */
24
25 /*-
26  * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
27  * otherwise caddr_t is not defined correctly
28  */
29
30 #include <X11/Intrinsic.h>
31
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35
36 #ifdef STANDALONE
37 # define PROGCLASS                                              "Screensaver"
38 # define HACK_INIT                                              init_screensaver
39 # define HACK_DRAW                                              draw_screensaver
40 # define HACK_RESHAPE                                   reshape_screensaver
41 # define screensaver_opts                               xlockmore_opts
42 #define DEFAULTS                        "*delay:                        10000   \n" \
43                                                                                 "*showFPS:              False   \n" \
44                                                                                 "*light:                        True    \n" \
45                                         "*wire:                         False   \n" \
46                                         "*texture:                      False   \n" \
47                                                                                 "*image:                        BUILTIN \n" \
48                                         "*name:             RANDOM  \n" \
49                                         "*example:          0       \n"
50
51 # include "xlockmore.h"                         /* from the xscreensaver distribution */
52 #else /* !STANDALONE */
53 # include "xlock.h"                                     /* from the xlockmore distribution */
54 #endif /* !STANDALONE */
55
56 #ifdef USE_GL /* whole file */
57
58 #ifdef HAVE_XMU
59 # ifndef VMS
60 #  include <X11/Xmu/Drawing.h>
61 #else  /* VMS */
62 #  include <Xmu/Drawing.h>
63 # endif /* VMS */
64 #endif
65
66 #include <stdlib.h>
67 #include <string.h>
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include <malloc.h>
71 #include <GL/gl.h>
72 #include <GL/glu.h>
73 #ifdef HAVE_GLE3
74 #include <GL/gle.h>
75 #else
76 #include <GL/tube.h>
77 #endif
78
79 #undef countof
80 #define countof(x) (sizeof((x))/sizeof((*x)))
81
82 #include "xpm-ximage.h"
83
84 #define checkImageWidth 64
85 #define checkImageHeight 64
86
87
88 extern void InitStuff_helix2(void);
89 extern void DrawStuff_helix2(void);
90 extern void InitStuff_helix3(void);
91 extern void DrawStuff_helix3(void);
92 extern void InitStuff_helix4(void);
93 extern void DrawStuff_helix4(void);
94 extern void InitStuff_joinoffset(void);
95 extern void DrawStuff_joinoffset(void);
96 extern void InitStuff_screw(void);
97 extern void DrawStuff_screw(void);
98 extern void InitStuff_taper(void);
99 extern void DrawStuff_taper(void);
100 extern void InitStuff_twistoid(void);
101 extern void DrawStuff_twistoid(void);
102
103
104
105 #define WIDTH 640
106 #define HEIGHT 480
107
108 #define DEF_LIGHT               "True"
109 #define DEF_WIRE                "False"
110 #define DEF_TEXTURE             "False"
111 #define DEF_TEXTURE_QUALITY   "False"
112 #define DEF_MIPMAP      "False"
113 #define DEF_NAME        "RANDOM"
114 #define DEF_IMAGE       "BUILTIN"
115
116 static int do_light;
117 static int do_wire;
118 static int do_texture;
119 static int do_texture_quality;
120 static int do_mipmap;
121 static char *which_name;
122 static char *which_image;
123
124 static XrmOptionDescRec opts[] = {
125   {"-light",   ".extrusion.light",     XrmoptionNoArg, (caddr_t) "true" },
126   {"+light",   ".extrusion.light",     XrmoptionNoArg, (caddr_t) "false" },
127   {"-wire",    ".extrusion.wire",      XrmoptionNoArg, (caddr_t) "true" },
128   {"+wire",    ".extrusion.wire",      XrmoptionNoArg, (caddr_t) "false" },
129   {"-texture", ".extrusion.texture",   XrmoptionNoArg, (caddr_t) "true" },
130   {"+texture", ".extrusion.texture",   XrmoptionNoArg, (caddr_t) "false" },
131   {"-texture", ".extrusion.texture",   XrmoptionNoArg, (caddr_t) "true" },
132   {"+texture_quality", ".extrusion.texture",   XrmoptionNoArg, (caddr_t) "false" },
133   {"-texture_quality", ".extrusion.texture",   XrmoptionNoArg, (caddr_t) "true" },
134   {"+mipmap", ".extrusion.mipmap",   XrmoptionNoArg, (caddr_t) "false" },
135   {"-mipmap", ".extrusion.mipmap",   XrmoptionNoArg, (caddr_t) "true" },
136   {"-name",   ".extrusion.name",  XrmoptionSepArg, (caddr_t) NULL },
137   {"-image",   ".extrusion.image",  XrmoptionSepArg, (caddr_t) NULL },
138 };
139
140
141 static argtype vars[] = {
142   {(caddr_t *) &do_light,    "light",   "Light",   DEF_LIGHT,   t_Bool},
143   {(caddr_t *) &do_wire,    "wire",   "Wire",   DEF_WIRE,   t_Bool},
144   {(caddr_t *) &do_texture,    "texture",   "Texture",   DEF_TEXTURE,   t_Bool},
145   {(caddr_t *) &do_texture_quality,    "texture_quality",   "Texture_Quality",   DEF_TEXTURE_QUALITY,   t_Bool},
146   {(caddr_t *) &do_mipmap,    "mipmap",   "Mipmap",   DEF_MIPMAP,   t_Bool},
147   {(caddr_t *) &which_name, "name",   "Name",   DEF_NAME,   t_String},
148   {(caddr_t *) &which_image, "image",   "Image",   DEF_IMAGE,   t_String},
149 };
150
151
152 static OptionStruct desc[] =
153 {
154   {"-name num", "example 'name' to draw (helix2, helix3, helix4, joinoffset, screw, taper, twistoid)"},
155   {"-/+ light", "whether to do enable lighting (slower)"},
156   {"-/+ wire", "whether to do use wireframe instead of filled (faster)"},
157   {"-/+ texture", "whether to apply a texture (slower)"},
158   {"-image <filename>", "texture image to load"},
159   {"-/+ texture_quality", "whether to use texture smoothing (slower)"},
160   {"-/+ mipmap", "whether to use texture mipmap (slower)"},
161 };
162
163 ModeSpecOpt screensaver_opts = {countof(opts), opts, countof(vars), vars, desc};
164
165 #ifdef USE_MODULES
166 ModStruct   screensaver_description =
167 {"screensaver", "init_screensaver", "draw_screensaver", "release_screensaver",
168  "draw_screensaver", "init_screensaver", NULL, &screensaver_opts,
169  1000, 1, 2, 1, 4, 1.0, "",
170  "OpenGL screensaver", 0, NULL};
171 #endif
172
173
174 /* structure for holding the screensaver data */
175 typedef struct {
176   int screen_width, screen_height;
177   GLXContext *glx_context;
178   Window window;
179   XColor fg, bg;
180 } screensaverstruct;
181 static screensaverstruct *Screensaver = NULL;
182
183
184
185
186 /* convenient access to the screen width */
187 static int global_width=640, global_height=480;
188
189 /* set up a light */
190 static GLfloat lightOnePosition[] = {40.0, 40, 100.0, 0.0};
191 static GLfloat lightOneColor[] = {0.99, 0.99, 0.99, 1.0}; 
192
193 static GLfloat lightTwoPosition[] = {-40.0, 40, 100.0, 0.0};
194 static GLfloat lightTwoColor[] = {0.99, 0.99, 0.99, 1.0}; 
195
196 float rot_x=0, rot_y=0, rot_z=0;
197 static float dx=0, dy=0, dz=0;
198 static float ddx=0, ddy=0, ddz=0;
199 static float d_max = 0;
200 static int screensaver_number;
201
202 static float max_lastx=300, max_lasty=400;
203 static float min_lastx=-400, min_lasty=-400;
204 static float d_lastx=0, d_lasty=0;
205 static float dd_lastx=0, dd_lasty=0;
206 static float max_dlastx=0, max_dlasty=0;
207 float lastx=0, lasty=0;
208
209 struct functions {
210   void (*InitStuff)(void);
211   void (*DrawStuff)(void);
212   char *name;
213 };
214
215 /* currently joinoffset and twistoid look funny-
216    like we're looking at them from the back or something
217 */
218
219 static struct functions funcs_ptr[] = {
220   {InitStuff_helix2, DrawStuff_helix2, "helix2"},
221   {InitStuff_helix3, DrawStuff_helix3, "helix3"},
222   {InitStuff_helix4, DrawStuff_helix4, "helix4"},
223   {InitStuff_joinoffset, DrawStuff_joinoffset, "joinoffset"},
224   {InitStuff_screw, DrawStuff_screw, "screw"},
225   {InitStuff_taper, DrawStuff_taper, "taper"},
226   {InitStuff_twistoid, DrawStuff_twistoid, "twistoid"},
227 };
228
229 static int num_screensavers = countof(funcs_ptr);
230
231
232 /* BEGINNING OF FUNCTIONS */
233
234
235 GLubyte *
236 Generate_Image(int *width, int *height, int *format)
237 {
238   GLubyte *result;
239   int i, j, c;
240   int counter=0;
241
242   *width = checkImageWidth;
243   *height = checkImageHeight;
244   result = (GLubyte *)malloc(4 * (*width) * (*height));
245
246   counter = 0;
247   for (i = 0; i < checkImageWidth; i++) {
248     for (j = 0; j < checkImageHeight; j++) {
249       c = (((((i&0x8)==0))^(((j&0x8))==0)))*255;
250       result[counter++] = (GLubyte) c;
251       result[counter++] = (GLubyte) c;
252       result[counter++] = (GLubyte) c;
253       result[counter++] = (GLubyte) 255;
254     }
255   }
256
257   *format = GL_RGBA;
258   return result;
259 }
260
261
262 /* Create a texture in OpenGL.  First an image is loaded 
263    and stored in a raster buffer, then it's  */
264 void Create_Texture(ModeInfo *mi, const char *filename)
265 {
266   int height, width;
267   GLubyte *image;
268   int format;
269
270   if ( !strncmp(filename, "BUILTIN", 7))
271     image = Generate_Image(&width, &height, &format);
272   else
273     {
274       XImage *ximage = xpm_file_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi),
275                                            MI_COLORMAP (mi), filename);
276       image  = ximage->data;
277       width  = ximage->width;
278       height = ximage->height;
279       format = GL_RGBA;
280     }
281
282   /* GL_MODULATE or GL_DECAL depending on what you want */
283   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
284   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
285   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
286   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
287   /* perhaps we can edge a bit more speed at the expense of quality */
288   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
289
290   if (do_texture_quality) {
291         /* with texture_quality, the min and mag filters look *much* nice but are *much* slower */
292         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
293         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
294   }
295   else {
296         /* default is to do it quick and dirty */
297         /* if you have mipmaps turned on, but not texture quality, nothing will happen! */
298         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
299         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
300   }
301
302   /* mipmaps make the image look much nicer */
303   if (do_mipmap)
304     {
305       int status;
306       clear_gl_error();
307       status = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, format,
308                                  GL_UNSIGNED_BYTE, image);
309       if (status)
310         {
311           const char *s = gluErrorString (status);
312           fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n",
313                    progname, width, height,
314                    (s ? s : "(unknown)"));
315           exit (1);
316         }
317       check_gl_error("mipmapping");
318     }
319   else
320     {
321       clear_gl_error();
322       glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0,
323                    format, GL_UNSIGNED_BYTE, image);
324       check_gl_error("texture");
325     }
326 }
327
328
329 /* mostly lifted from lament.c */
330 static void
331 rotate (float *pos, float *v, float *dv, float max_v)
332 {
333   double ppos = *pos;
334
335   /* tick position */
336   if (ppos < 0)
337     ppos = -(ppos + *v);
338   else
339     ppos += *v;
340
341   if (ppos > 360)
342     ppos -= 360;
343   else if (ppos < 0)
344     ppos += 360;
345
346   if (ppos < 0) abort();
347   if (ppos > 360) abort();
348   *pos = (*pos > 0 ? ppos : -ppos);
349
350   /* accelerate */
351   *v += *dv;
352
353   /* clamp velocity */
354   if (*v > max_v || *v < -max_v)
355     {
356       *dv = -*dv;
357     }
358   /* If it stops, start it going in the other direction. */
359   else if (*v < 0)
360     {
361       if (random() % 4)
362         {
363           *v = 0;
364
365           /* keep going in the same direction */
366           if (random() % 2)
367             *dv = 0;
368           else if (*dv < 0)
369             *dv = -*dv;
370         }
371       else
372         {
373           /* reverse gears */
374           *v = -*v;
375           *dv = -*dv;
376           *pos = -*pos;
377         }
378     }
379
380   /* Alter direction of rotational acceleration randomly. */
381   if (! (random() % 120))
382     *dv = -*dv;
383
384   /* Change acceleration very occasionally. */
385   if (! (random() % 200))
386     {
387       if (*dv == 0)
388         *dv = 0.00001;
389       else if (random() & 1)
390         *dv *= 1.2;
391       else
392         *dv *= 0.8;
393     }
394 }
395
396
397 static void
398 bounce (float *pos, float *v, float *dv, float max_v)
399 {
400   *pos += *v;
401
402   if (*pos > 1.0)
403     *pos = 1.0, *v = -*v, *dv = -*dv;
404   else if (*pos < 0)
405     *pos = 0, *v = -*v, *dv = -*dv;
406
407   if (*pos < 0.0) abort();
408   if (*pos > 1.0) abort();
409
410   /* accelerate */
411   *v += *dv;
412
413   /* clamp velocity */
414   if (*v > max_v || *v < -max_v)
415     {
416       *dv = -*dv;
417     }
418
419   /* Alter direction of rotational acceleration randomly. */
420   if (! (random() % 120))
421     *dv = -*dv;
422
423   /* Change acceleration very occasionally. */
424   if (! (random() % 200))
425     {
426       if (*dv == 0)
427         *dv = 0.00001;
428       else if (random() & 1)
429         *dv *= 1.2;
430       else
431         *dv *= 0.8;
432     }
433 }
434
435
436 static void
437 init_rotation (void)
438 {
439   rot_x = (float) (random() % (360 * 2)) - 360;  /* -360 - 360 */
440   rot_y = (float) (random() % (360 * 2)) - 360;
441   rot_z = (float) (random() % (360 * 2)) - 360;
442
443   /* bell curve from 0-1.5 degrees, avg 0.75 */
444   dx = (frand(1) + frand(1) + frand(1)) / 2.0;
445   dy = (frand(1) + frand(1) + frand(1)) / 2.0;
446   dz = (frand(1) + frand(1) + frand(1)) / 2.0;
447
448   d_max = dx * 2;
449
450   ddx = 0.004;
451   ddy = 0.004;
452   ddz = 0.004;
453
454   lastx = (random() % (int) (max_lastx - min_lastx)) + min_lastx;
455   lasty = (random() % (int) (max_lasty - min_lasty)) + min_lasty;
456   d_lastx = (frand(1) + frand(1) + frand(1));
457   d_lasty = (frand(1) + frand(1) + frand(1));
458   max_dlastx = d_lastx * 2;
459   max_dlasty = d_lasty * 2;
460   dd_lastx = 0.004;
461   dd_lasty = 0.004;
462 }
463
464
465 /* draw the screensaver once */
466 void draw_screensaver(ModeInfo * mi)
467 {
468   screensaverstruct *gp = &Screensaver[MI_SCREEN(mi)];
469   Display    *display = MI_DISPLAY(mi);
470   Window      window = MI_WINDOW(mi);
471
472   Window root, child;
473   int rootx, rooty, winx, winy;
474   unsigned int mask;
475   XEvent event;
476
477   if (!gp->glx_context)
478         return;
479
480   glXMakeCurrent(display, window, *(gp->glx_context));
481
482   funcs_ptr[screensaver_number].DrawStuff();
483           
484   rotate(&rot_x, &dx, &ddx, d_max);
485   rotate(&rot_y, &dy, &ddy, d_max);
486   rotate(&rot_z, &dz, &ddz, d_max);
487
488   /* swallow any ButtonPress events */
489   while (XCheckMaskEvent (MI_DISPLAY(mi), ButtonPressMask, &event))
490     ;
491   /* check the pointer position and button state. */
492   XQueryPointer (MI_DISPLAY(mi), MI_WINDOW(mi),
493                  &root, &child, &rootx, &rooty, &winx, &winy, &mask);
494
495   /* track the mouse only if a button is down. */
496   if (mask & (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask))
497     {
498       lastx = winx;
499       lasty = winy;
500     }
501   else
502     {
503       float scale = (max_lastx - min_lastx);
504       lastx -= min_lastx;
505       lasty -= min_lasty;
506       lastx /= scale;
507       lasty /= scale;
508       d_lastx /= scale;
509       d_lasty /= scale;
510       dd_lastx /= scale;
511       dd_lasty /= scale;
512       bounce(&lastx, &d_lastx, &dd_lastx, max_dlastx);
513       bounce(&lasty, &d_lasty, &dd_lasty, max_dlasty);
514       lastx *= scale;
515       lasty *= scale;
516       lastx += min_lastx;
517       lasty += min_lasty;
518       d_lastx *= scale;
519       d_lasty *= scale;
520       dd_lastx *= scale;
521       dd_lasty *= scale;
522     }
523
524   if (mi->fps_p) do_fps (mi);
525   glXSwapBuffers(display, window);
526 }
527
528
529 /* set up lighting conditions */
530 static void SetupLight(void)
531 {
532   glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition);
533   glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor);
534   glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition);
535   glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor);
536
537   glEnable (GL_LIGHT0);
538   glEnable (GL_LIGHT1);
539   glEnable (GL_LIGHTING);
540
541   glColorMaterial (GL_FRONT, GL_DIFFUSE);
542   glColorMaterial (GL_BACK, GL_DIFFUSE);
543   glEnable (GL_COLOR_MATERIAL);
544 }
545
546 /* reset the projection matrix */
547 static void resetProjection(void) {
548   glMatrixMode(GL_PROJECTION);
549   glLoadIdentity();
550   glFrustum (-9, 9, -9, 9, 50, 150.0);
551   glMatrixMode(GL_MODELVIEW);
552   glLoadIdentity();
553 }
554
555 /* Standard reshape function */
556 void
557 reshape_screensaver(ModeInfo *mi, int width, int height)
558 {
559   global_width=width;
560   global_height=height;
561   glViewport( 0, 0, global_width, global_height );
562   resetProjection();
563 }
564
565
566 /* decide which screensaver example to run */
567 static void chooseScreensaverExample(void) {
568   int i;
569   /* call the extrusion init routine */
570
571   if (!strncmp(which_name, "RANDOM", strlen(which_name))) {
572     screensaver_number = random() % num_screensavers;
573   }
574   else {
575         screensaver_number=-1;
576         for (i=0; i < num_screensavers; i++) {
577           if (!strncmp(which_name, funcs_ptr[i].name, strlen(which_name))) {
578                 screensaver_number = i;
579           }
580         }         
581   }
582         
583   if (screensaver_number < 0 || screensaver_number >= num_screensavers) {
584         fprintf(stderr, "%s: invalid screensaver example number!\n", progname);
585         fprintf(stderr, "%s: known screensavers:\n", progname);
586         for (i=0; i < num_screensavers; i++)
587           fprintf(stderr,"\t%s\n", funcs_ptr[i].name);
588         exit(1);
589   }
590   init_rotation();
591   funcs_ptr[screensaver_number].InitStuff();
592 }
593
594 /* main OpenGL initialization routine */
595 static void
596 initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) 
597 {
598   int style;
599   int mode;
600
601   reshape_screensaver(mi, width, height);
602   glViewport( 0, 0, width, height ); 
603
604   glEnable(GL_DEPTH_TEST);
605   glClearColor(0,0,0,0);
606 /*    glCullFace(GL_BACK); */
607 /*    glEnable(GL_CULL_FACE); */
608   glShadeModel(GL_SMOOTH);
609
610   if (do_light)
611         SetupLight();
612   if (do_wire) {
613         glPolygonMode(GL_FRONT,GL_LINE);
614         glPolygonMode(GL_BACK,GL_LINE);
615   }
616   if (do_texture) {
617         Create_Texture(mi, which_image);
618         glEnable(GL_TEXTURE_2D);
619
620         /* configure the pipeline */
621         style = TUBE_JN_CAP;
622         style |= TUBE_CONTOUR_CLOSED;
623         style |= TUBE_NORM_FACET;
624         style |= TUBE_JN_ANGLE;
625         gleSetJoinStyle (style);
626
627         if (do_texture) {
628           mode = GLE_TEXTURE_ENABLE | GLE_TEXTURE_VERTEX_MODEL_FLAT;
629           glMatrixMode (GL_TEXTURE); glLoadIdentity ();
630           glScalef (0.25, 0.1, 1); glMatrixMode (GL_MODELVIEW);
631           gleTextureMode (mode);
632         }
633   }
634
635 }
636
637 /* xscreensaver initialization routine */
638 void init_screensaver(ModeInfo * mi)
639 {
640   int screen = MI_SCREEN(mi);
641   screensaverstruct *gp;
642
643   if (Screensaver == NULL) {
644         if ((Screensaver = (screensaverstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (screensaverstruct))) == NULL)
645           return;
646   }
647   gp = &Screensaver[screen];
648
649   gp->window = MI_WINDOW(mi);
650   if ((gp->glx_context = init_GL(mi)) != NULL) {
651         reshape_screensaver(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
652         initializeGL(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
653         chooseScreensaverExample();
654   } else {
655         MI_CLEARWINDOW(mi);
656   }
657
658 }
659
660 /* all sorts of nice cleanup code should go here! */
661 void release_screensaver(ModeInfo * mi)
662 {
663   int screen;
664   if (Screensaver != NULL) {
665         for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
666           /*      screensaverstruct *gp = &Screensaver[screen];*/
667         }
668         (void) free((void *) Screensaver);
669         Screensaver = NULL;
670   }
671   FreeAllGL(mi);
672 }
673 #endif
674