http://svn.poeml.de/viewvc/ppc/src-unpacked/xscreensaver/xscreensaver-4.12.tar.bz2...
[xscreensaver] / hacks / glx / atlantis.c
1 /* atlantis --- Shows moving 3D sea animals */
2
3 #if !defined( lint ) && !defined( SABER )
4 static const char sccsid[] = "@(#)atlantis.c    5.08 2003/04/09 xlockmore";
5
6 #endif
7
8 /* Copyright (c) E. Lassauge, 1998. */
9
10 /*
11  * Permission to use, copy, modify, and distribute this software and its
12  * documentation for any purpose and without fee is hereby granted,
13  * provided that the above copyright notice appear in all copies and that
14  * both that copyright notice and this permission notice appear in
15  * supporting documentation.
16  *
17  * This file is provided AS IS with no warranties of any kind.  The author
18  * shall have no liability with respect to the infringement of copyrights,
19  * trade secrets or any patents by this file or any part thereof.  In no
20  * event will the author be liable for any lost revenue or profits or
21  * other special, indirect and consequential damages.
22  *
23  * The original code for this mode was written by Mark J. Kilgard
24  * as a demo for openGL programming.
25  * 
26  * Porting it to xlock  was possible by comparing the original Mesa's morph3d 
27  * demo with it's ported version to xlock, so thanks for Marcelo F. Vianna 
28  * (look at morph3d.c) for his indirect help.
29  *
30  * Thanks goes also to Brian Paul for making it possible and inexpensive
31  * to use OpenGL at home.
32  *
33  * My e-mail address is lassauge@mail.dotcom.fr
34  *
35  * Eric Lassauge  (May-13-1998)
36  *
37  * REVISION HISTORY:
38  * 
39  * Jamie Zawinski, 2-Apr-01:  - The fishies were inside out!  The back faces
40  *                              were being drawn, not the front faces.
41  *                            - Added a texture to simulate light from the
42  *                              surface, like in the SGI version.
43  *
44  * David A. Bagley - 98/06/17 : Add whalespeed option. Global options to
45  *                              initialize local variables are now:
46  *                              XLock.atlantis.cycles: 100      ! SharkSpeed
47  *                              XLock.atlantis.batchcount: 4    ! SharkNum
48  *                              XLock.atlantis.whalespeed: 250  ! WhaleSpeed
49  *                              XLock.atlantis.size: 6000       ! SharkSize
50  *                              Add random direction for whales/dolphins
51  * 
52  * E.Lassauge - 98/06/16: Use the following global options to initialize
53  *                        local variables :
54  *                              XLock.atlantis.delay: 100       ! SharkSpeed
55  *                              XLock.atlantis.batchcount: 4    ! SharkNum
56  *                              XLock.atlantis.cycles: 250      ! WhaleSpeed
57  *                              XLock.atlantis.size: 6000       ! SharkSize
58  *                        Add support for -/+ wireframe (t'was so easy to do!)
59  *
60  * TODO : 
61  *        - add a sort of background image or random bg color
62  *        - better handling of sizes and speeds
63  *        - test standalone and module modes
64  *        - purify it (!)
65  */
66
67 /* Copyright (c) Mark J. Kilgard, 1994. */
68
69 /**
70  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
71  * ALL RIGHTS RESERVED
72  * Permission to use, copy, modify, and distribute this software for
73  * any purpose and without fee is hereby granted, provided that the above
74  * copyright notice appear in all copies and that both the copyright notice
75  * and this permission notice appear in supporting documentation, and that
76  * the name of Silicon Graphics, Inc. not be used in advertising
77  * or publicity pertaining to distribution of the software without specific,
78  * written prior permission.
79  *
80  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
81  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
82  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
83  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
84  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
85  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
86  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
87  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
88  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
89  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
90  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
91  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
92  *
93  * US Government Users Restricted Rights
94  * Use, duplication, or disclosure by the Government is subject to
95  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
96  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
97  * clause at DFARS 252.227-7013 and/or in similar or successor
98  * clauses in the FAR or the DOD or NASA FAR Supplement.
99  * Unpublished-- rights reserved under the copyright laws of the
100  * United States.  Contractor/manufacturer is Silicon Graphics,
101  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
102  *
103  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
104  */
105
106 #define DEF_TEXTURE "True"
107 #define DEF_GRADIENT "False"
108 #define DEF_WHALESPEED  "250"
109
110 #ifdef STANDALONE
111 # define PROGCLASS      "Atlantis"
112 # define HACK_INIT      init_atlantis
113 # define HACK_DRAW      draw_atlantis
114 # define HACK_RESHAPE   reshape_atlantis
115 # define atlantis_opts  xlockmore_opts
116 # define DEFAULTS       "*delay:       25000 \n" \
117                          "*count:          4 \n" \
118                          "*showFPS:    False \n" \
119                          "*cycles:       100 \n" \
120                          "*size:        6000 \n" \
121                          "*wireframe:  False \n" \
122                          "*texture:    " DEF_TEXTURE    " \n" \
123                          "*gradient:   " DEF_GRADIENT   " \n" \
124                          "*whalespeed: " DEF_WHALESPEED " \n"
125 # include "xlockmore.h"         /* from the xscreensaver distribution */
126 #else  /* !STANDALONE */
127 # include "xlock.h"             /* from the xlockmore distribution */
128 #include "vis.h"
129 #endif /* !STANDALONE */
130
131 #ifdef USE_GL
132
133 #include "atlantis.h"
134 #include <GL/glu.h>
135
136
137 static int  whalespeed;
138 static int do_texture;
139 static int do_gradient;
140 static XrmOptionDescRec opts[] =
141 {
142      {"-whalespeed", ".atlantis.whalespeed", XrmoptionSepArg, (caddr_t) NULL},
143      {"-texture",    ".atlantis.texture",    XrmoptionNoArg, (caddr_t)"true"},
144      {"+texture",    ".atlantis.texture",    XrmoptionNoArg, (caddr_t)"false"},
145      {"-gradient",   ".atlantis.gradient",   XrmoptionNoArg, (caddr_t)"true"},
146      {"+gradient",   ".atlantis.gradient",   XrmoptionNoArg, (caddr_t)"false"},
147 };
148
149 static argtype vars[] =
150 {
151  {(caddr_t *) & whalespeed, "whalespeed", "WhaleSpeed", DEF_WHALESPEED, t_Int},
152  {(caddr_t *) &do_texture,  "texture",    "Texture",    DEF_TEXTURE,   t_Bool},
153  {(caddr_t *) &do_gradient, "gradient",   "Gradient",   DEF_GRADIENT,  t_Bool},
154 };
155
156 static OptionStruct desc[] =
157 {
158         {"-whalespeed num", "speed of whales and the dolphin"},
159         {"-texture num",    "whether to introduce water-like distortion"}
160 };
161
162 ModeSpecOpt atlantis_opts =
163 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
164
165 #ifdef USE_MODULES
166 ModStruct   atlantis_description =
167 {"atlantis", "init_atlantis", "draw_atlantis", "release_atlantis",
168  "refresh_atlantis", "change_atlantis", NULL, &atlantis_opts,
169  1000, NUM_SHARKS, SHARKSPEED, SHARKSIZE, 64, 1.0, "",
170  "Shows moving sharks/whales/dolphin", 0, NULL};
171
172 #endif
173
174 static atlantisstruct *atlantis = NULL;
175
176 #include "xpm-ximage.h"
177
178 #include "../images/sea-texture.xpm"
179
180
181 static void
182 parse_image_data(ModeInfo *mi)
183 {
184   atlantisstruct *ap = &atlantis[MI_SCREEN(mi)];
185   ap->texture = xpm_to_ximage (mi->dpy,
186                                mi->xgwa.visual,
187                                mi->xgwa.colormap,
188                                sea_texture);
189 }
190
191 static void
192 InitFishs(atlantisstruct * ap)
193 {
194         int         i;
195
196         for (i = 0; i < ap->num_sharks; i++) {
197                 ap->sharks[i].x = 70000.0 + NRAND(ap->sharksize);
198                 ap->sharks[i].y = NRAND(ap->sharksize);
199                 ap->sharks[i].z = NRAND(ap->sharksize);
200                 ap->sharks[i].psi = NRAND(360) - 180.0;
201                 ap->sharks[i].v = 1.0;
202         }
203
204         /* Random whale direction */
205         ap->whaledir = LRAND() & 1;
206
207         ap->dolph.x = 30000.0;
208         ap->dolph.y = 0.0;
209         ap->dolph.z = (float) (ap->sharksize);
210         ap->dolph.psi = (ap->whaledir) ? 90.0 : -90.0;
211         ap->dolph.theta = 0.0;
212         ap->dolph.v = 6.0;
213
214         ap->momWhale.x = 70000.0;
215         ap->momWhale.y = 0.0;
216         ap->momWhale.z = 0.0;
217         ap->momWhale.psi = (ap->whaledir) ? 90.0 : -90.0;
218         ap->momWhale.theta = 0.0;
219         ap->momWhale.v = 3.0;
220
221         ap->babyWhale.x = 60000.0;
222         ap->babyWhale.y = -2000.0;
223         ap->babyWhale.z = -2000.0;
224         ap->babyWhale.psi = (ap->whaledir) ? 90.0 : -90.0;
225         ap->babyWhale.theta = 0.0;
226         ap->babyWhale.v = 3.0;
227 }
228
229 static void
230 Init(ModeInfo *mi)
231 {
232         atlantisstruct *ap = &atlantis[MI_SCREEN(mi)];
233
234         static float ambient[] =
235         {0.1, 0.1, 0.1, 1.0};
236         static float diffuse[] =
237         {1.0, 1.0, 1.0, 1.0};
238         static float position[] =
239         {0.0, 1.0, 0.0, 0.0};
240         static float mat_shininess[] =
241         {90.0};
242         static float mat_specular[] =
243         {0.8, 0.8, 0.8, 1.0};
244         static float mat_diffuse[] =
245         {0.46, 0.66, 0.795, 1.0};
246         static float mat_ambient[] =
247         {0.0, 0.1, 0.2, 1.0};
248         static float lmodel_ambient[] =
249         {0.4, 0.4, 0.4, 1.0};
250         static float lmodel_localviewer[] =
251         {0.0};
252         float        fblue = 0.0, fgreen;
253
254         glFrontFace(GL_CCW);
255
256         if (ap->wire)
257           {
258             glDisable(GL_DEPTH_TEST);
259             glDisable(GL_CULL_FACE);
260             glDisable(GL_LIGHTING);
261             glDisable(GL_NORMALIZE);
262           }
263         else
264           {
265             glDepthFunc(GL_LEQUAL);
266             glEnable(GL_DEPTH_TEST);
267             glEnable(GL_CULL_FACE);
268             glEnable(GL_NORMALIZE);
269             glShadeModel(GL_SMOOTH);
270
271             glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
272             glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
273             glLightfv(GL_LIGHT0, GL_POSITION, position);
274             glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
275             glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);
276             glEnable(GL_LIGHTING);
277             glEnable(GL_LIGHT0);
278
279             glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
280             glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
281             glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
282             glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
283           }
284
285         if (ap->wire || !do_texture)
286           {
287             glDisable(GL_TEXTURE_2D);
288           }
289         else
290           {
291             GLfloat s_plane[] = { 1, 0, 0, 0 };
292             GLfloat t_plane[] = { 0, 0, 1, 0 };
293             GLfloat scale = 0.0005;
294
295             if (!ap->texture)
296               parse_image_data (mi);
297
298             clear_gl_error();
299             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
300                          ap->texture->width, ap->texture->height, 0,
301                          GL_RGBA, GL_UNSIGNED_BYTE,
302                          ap->texture->data);
303             check_gl_error("texture");
304
305             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
306             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
307             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
308             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
309
310             glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
311
312             glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
313             glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
314             glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
315             glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
316
317             glEnable(GL_TEXTURE_GEN_S);
318             glEnable(GL_TEXTURE_GEN_T);
319             glEnable(GL_TEXTURE_2D);
320
321             glMatrixMode(GL_TEXTURE);
322             glLoadIdentity();
323             glScalef(scale, scale, 1);
324             glMatrixMode(GL_MODELVIEW);
325           }
326
327         InitFishs(ap);
328
329         /* Add a little randomness */
330         fblue = ((float) (NRAND(30)) / 100.0) + 0.70;
331         fgreen = fblue * 0.56;
332         glClearColor(0.0, fgreen, fblue, 0.0);
333 }
334
335 void
336 reshape_atlantis(ModeInfo * mi, int width, int height)
337 {
338         atlantisstruct *ap = &atlantis[MI_SCREEN(mi)];
339
340         glViewport(0, 0, ap->WinW = (GLint) width, ap->WinH = (GLint) height);
341
342         glMatrixMode(GL_PROJECTION);
343         glLoadIdentity();
344         gluPerspective(400.0, (GLdouble) width / (GLdouble) height, 1.0, 2000000.0);
345         glMatrixMode(GL_MODELVIEW);
346 }
347
348
349 /* jwz -- this doesn't really work very well.
350
351    All I want to do is give the tank a gradient-filled background, instead
352    of just solid blue.  The following was my guess as to how to do this,
353    but it kills my frame rate.  I guess there's a more efficient way to do
354    this, but I don't see it...
355
356    I mean, all I want to do is dump some non-projected bytes into the color
357    buffer, then zero out the depth buffer.  That *can't* be expensive, can
358    it?
359  */
360 static void
361 clear_tank (atlantisstruct * ap)
362 {
363   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
364
365   if (do_gradient && !ap->wire)
366     {
367       static GLuint gradient_list = 0;
368       static GLuint gradient_tex = 0;
369
370       if (gradient_list == 0)
371         {
372           unsigned char *pixels = 0;
373           int start = 64;
374           int end = start + 128;
375           int size = 4 * (end - start);
376           int i;
377
378           pixels = (unsigned char *) malloc (size);
379           i = 0;
380           while (i < size)
381             {
382               pixels[i] = 0; i++;
383               pixels[i] = (start + (i>>2)) * 0.56; i++;
384               pixels[i] = (start + (i>>2)); i++;
385               pixels[i] = 255; i++;
386             }
387
388           clear_gl_error();
389
390           glGenTextures(1, &gradient_tex);
391           glBindTexture(GL_TEXTURE_1D, gradient_tex);
392
393           glTexImage1D(GL_TEXTURE_1D, 0, 4,
394                        (end - start), 0,
395                        GL_RGBA, GL_UNSIGNED_BYTE, pixels);
396           check_gl_error ("gradient texture");
397           glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
398           glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
399
400
401           gradient_list = glGenLists(1);
402           glNewList(gradient_list, GL_COMPILE);
403
404           glDepthMask (False);
405           glDisable(GL_DEPTH_TEST);
406           glDisable(GL_LIGHTING);
407           glDisable(GL_TEXTURE_2D);
408           glEnable(GL_TEXTURE_1D);
409           glBindTexture(GL_TEXTURE_1D, gradient_tex);
410           glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 
411           glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
412
413           glMatrixMode(GL_PROJECTION);
414           glPushMatrix();
415           glLoadIdentity();
416           glRotatef(90, 0, 0, 1);
417           glTranslatef(-1, -1, 0);
418           glScalef(2, 2, 1);
419
420           glBegin(GL_QUADS);
421           glTexCoord1i(1); glVertex3i(1, 0, 0);
422           glTexCoord1i(0); glVertex3i(0, 0, 0);
423           glTexCoord1i(0); glVertex3i(0, 1, 0);
424           glTexCoord1i(1); glVertex3i(1, 1, 0);
425           glEnd();
426
427           glPopMatrix();
428
429           glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
430           glDisable(GL_TEXTURE_1D);
431
432           glDepthMask (True);
433           glEnable(GL_DEPTH_TEST);
434           glEnable(GL_CULL_FACE);
435           glEnable(GL_LIGHTING);
436           if (do_texture)
437             glEnable(GL_TEXTURE_2D);
438
439           glEndList();
440           check_gl_error ("gradient list");
441         }
442
443       glCallList(gradient_list);
444     }
445 }
446
447
448 static void
449 Animate(atlantisstruct * ap)
450 {
451         int         i;
452
453         for (i = 0; i < ap->num_sharks; i++) {
454                 SharkPilot(&(ap->sharks[i]), ap->sharkspeed);
455                 SharkMiss(ap, i);
456         }
457         WhalePilot(&(ap->dolph), ap->whalespeed, ap->whaledir);
458         ap->dolph.phi++;
459         WhalePilot(&(ap->momWhale), ap->whalespeed, ap->whaledir);
460         ap->momWhale.phi++;
461         WhalePilot(&(ap->babyWhale), ap->whalespeed, ap->whaledir);
462         ap->babyWhale.phi++;
463 }
464
465 static void
466 AllDisplay(atlantisstruct * ap)
467 {
468         int         i;
469
470         clear_tank(ap);
471
472         for (i = 0; i < ap->num_sharks; i++) {
473                 glPushMatrix();
474                 FishTransform(&(ap->sharks[i]));
475                 DrawShark(&(ap->sharks[i]), ap->wire);
476                 glPopMatrix();
477         }
478
479         glPushMatrix();
480         FishTransform(&(ap->dolph));
481         DrawDolphin(&(ap->dolph), ap->wire);
482         glPopMatrix();
483
484         glPushMatrix();
485         FishTransform(&(ap->momWhale));
486         DrawWhale(&(ap->momWhale), ap->wire);
487         glPopMatrix();
488
489         glPushMatrix();
490         FishTransform(&(ap->babyWhale));
491         glScalef(0.45, 0.45, 0.3);
492         DrawWhale(&(ap->babyWhale), ap->wire);
493         glPopMatrix();
494 }
495
496 /*
497  *-----------------------------------------------------------------------------
498  *-----------------------------------------------------------------------------
499  *    Xlock hooks.
500  *-----------------------------------------------------------------------------
501  *-----------------------------------------------------------------------------
502  */
503
504 /*
505  *-----------------------------------------------------------------------------
506  *    Initialize atlantis.  Called each time the window changes.
507  *-----------------------------------------------------------------------------
508  */
509
510 void
511 init_atlantis(ModeInfo * mi)
512 {
513         int         screen = MI_SCREEN(mi);
514         atlantisstruct *ap;
515         Display    *display = MI_DISPLAY(mi);
516         Window      window = MI_WINDOW(mi);
517
518         if (atlantis == NULL) {
519                 if ((atlantis = (atlantisstruct *) calloc(MI_NUM_SCREENS(mi),
520                                            sizeof (atlantisstruct))) == NULL)
521                         return;
522         }
523         ap = &atlantis[screen];
524         ap->num_sharks = MI_COUNT(mi);
525         if (ap->sharks == NULL) {
526                 if ((ap->sharks = (fishRec *) calloc(ap->num_sharks,
527                                                 sizeof (fishRec))) == NULL) {
528                         /* free everything up to now */
529                         (void) free((void *) atlantis);
530                         atlantis = NULL;
531                         return;
532                 }
533         }
534         ap->sharkspeed = MI_CYCLES(mi);         /* has influence on the "width"
535                                                    of the movement */
536         ap->sharksize = MI_SIZE(mi);    /* has influence on the "distance"
537                                            of the sharks */
538         ap->whalespeed = whalespeed;
539         ap->wire = MI_IS_WIREFRAME(mi);
540
541         if (MI_IS_DEBUG(mi)) {
542                 (void) fprintf(stderr,
543                                "%s:\n\tnum_sharks=%d\n\tsharkspeed=%.1f\n\tsharksize=%d\n\twhalespeed=%.1f\n\twireframe=%s\n",
544                                MI_NAME(mi),
545                                ap->num_sharks,
546                                ap->sharkspeed,
547                                ap->sharksize,
548                                ap->whalespeed,
549                                ap->wire ? "yes" : "no"
550                         );
551         }
552         if ((ap->glx_context = init_GL(mi)) != NULL) {
553
554                 reshape_atlantis(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
555                 glDrawBuffer(GL_BACK);
556                 Init(mi);
557                 AllDisplay(ap);
558                 glXSwapBuffers(display, window);
559
560         } else {
561                 MI_CLEARWINDOW(mi);
562         }
563 }
564
565 /*
566  *-----------------------------------------------------------------------------
567  *    Called by the mainline code periodically to update the display.
568  *-----------------------------------------------------------------------------
569  */
570 void
571 draw_atlantis(ModeInfo * mi)
572 {
573         atlantisstruct *ap = &atlantis[MI_SCREEN(mi)];
574
575         Display    *display = MI_DISPLAY(mi);
576         Window      window = MI_WINDOW(mi);
577
578         MI_IS_DRAWN(mi) = True;
579
580         if (!ap->glx_context)
581                 return;
582
583         glXMakeCurrent(display, window, *(ap->glx_context));
584
585         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
586
587         AllDisplay(ap);
588         Animate(ap);
589
590         if (mi->fps_p) do_fps (mi);
591         glXSwapBuffers(display, window);
592 }
593
594
595 /*
596  *-----------------------------------------------------------------------------
597  *    The display is being taken away from us.  Free up malloc'ed 
598  *      memory and X resources that we've alloc'ed.  Only called
599  *      once, we must zap everything for every screen.
600  *-----------------------------------------------------------------------------
601  */
602
603 void
604 release_atlantis(ModeInfo * mi)
605 {
606         int         screen;
607
608         if (atlantis != NULL) {
609                 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
610                         atlantisstruct *ap = &atlantis[screen];
611
612                         if (ap->sharks)
613                                 (void) free((void *) ap->sharks);
614                 }
615                 (void) free((void *) atlantis);
616                 atlantis = NULL;
617         }
618         FreeAllGL(mi);
619 }
620
621 void
622 refresh_atlantis(ModeInfo * mi)
623 {
624 }
625
626 void
627 change_atlantis(ModeInfo * mi)
628 {
629         atlantisstruct *ap = &atlantis[MI_SCREEN(mi)];
630
631         if (!ap->glx_context)
632                 return;
633
634         glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(ap->glx_context));
635         Init(mi);
636 }
637
638 #endif /* USE_GL */