From http://www.jwz.org/xscreensaver/xscreensaver-5.16.tar.gz
[xscreensaver] / hacks / glx / pipes.c
1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* pipes --- 3D selfbuiding pipe system */
3
4 #if 0
5 static const char sccsid[] = "@(#)pipes.c       4.07 97/11/24 xlockmore";
6 #endif
7
8 /*-
9  * Permission to use, copy, modify, and distribute this software and its
10  * documentation for any purpose and without fee is hereby granted,
11  * provided that the above copyright notice appear in all copies and that
12  * both that copyright notice and this permission notice appear in
13  * supporting documentation.
14  *
15  * This file is provided AS IS with no warranties of any kind.  The author
16  * shall have no liability with respect to the infringement of copyrights,
17  * trade secrets or any patents by this file or any part thereof.  In no
18  * event will the author be liable for any lost revenue or profits or
19  * other special, indirect and consequential damages.
20  *
21  * This program was inspired on a WindowsNT(R)'s screen saver. It was written 
22  * from scratch and it was not based on any other source code.
23  *
24  * ==========================================================================
25  * The routine myElbow is derivated from the doughnut routine from the MesaGL
26  * library (more especifically the Mesaaux library) written by Brian Paul.
27  * ==========================================================================
28  *
29  * Thanks goes to Brian Paul for making it possible and inexpensive to use
30  * OpenGL at home.
31  *
32  * Since I'm not a native English speaker, my apologies for any grammatical
33  * mistake.
34  *
35  * My e-mail address is
36  * m-vianna@usa.net
37  * Marcelo F. Vianna (Apr-09-1997)
38  *
39  * Revision History:
40  * 29-Apr-97: Factory equipment by Ed Mackey.  Productive day today, eh?
41  * 29-Apr-97: Less tight turns Jeff Epler <jepler@inetnebr.com>
42  * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna
43  */
44
45 #ifdef STANDALONE
46 # define DEFAULTS       "*delay:                10000   \n"                     \
47                                         "*count:                2       \n"                     \
48                                         "*cycles:               5       \n"                     \
49                                         "*size:                 500     \n"                     \
50                         "*showFPS:      False   \n"                 \
51                         "*fpsSolid:     True    \n"
52
53 # define refresh_pipes 0
54 # define pipes_handle_event 0
55 # include "xlockmore.h"                         /* from the xscreensaver distribution */
56 #else  /* !STANDALONE */
57 # include "xlock.h"                                     /* from the xlockmore distribution */
58 #endif /* !STANDALONE */
59
60 #ifdef USE_GL
61
62 #ifdef HAVE_COCOA
63 # include "jwxyz.h"
64 #else
65 # include <X11/Xlib.h>
66 # include <GL/gl.h>
67 # include <GL/glu.h>
68 #endif
69
70 #ifdef HAVE_JWZGLES
71 # include "jwzgles.h"
72 #endif /* HAVE_JWZGLES */
73
74 #include "sphere.h"
75 #include "buildlwo.h"
76 #include "teapot.h"
77
78 #define DEF_FACTORY     "2"
79 #define DEF_FISHEYE     "True"
80 #define DEF_TIGHTTURNS  "False"
81 #define DEF_ROTATEPIPES "True"
82 #define DEF_DBUF        "False"
83 #define NofSysTypes     3
84
85 static int  factory;
86 static Bool fisheye, tightturns, rotatepipes;
87 static Bool dbuf_p;
88
89 static XrmOptionDescRec opts[] =
90 {
91         {"-factory", ".pipes.factory", XrmoptionSepArg, 0},
92         {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, "on"},
93         {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, "off"},
94         {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, "on"},
95         {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, "off"},
96       {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "on"},
97       {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "off"},
98       {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, "on"},
99       {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, "off"},
100 };
101 static argtype vars[] =
102 {
103         {&factory, "factory", "Factory", DEF_FACTORY, t_Int},
104         {&fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
105         {&tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
106         {&rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool},
107         {&dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool}
108 };
109 static OptionStruct desc[] =
110 {
111         {"-factory num", "how much extra equipment in pipes (0 for none)"},
112         {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
113         {"-/+tightturns", "turn on/off tight turns"},
114         {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"},
115         {"-/+db", "turn on/off double buffering"}
116 };
117
118 ENTRYPOINT ModeSpecOpt pipes_opts =
119 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
120
121 #ifdef USE_MODULES
122 ModStruct   pipes_description =
123 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
124  "draw_pipes",
125  "change_pipes", NULL, &pipes_opts,
126  1000, 2, 5, 500, 4, 1.0, "",
127  "Shows a selfbuilding pipe system", 0, NULL};
128
129 #endif
130
131 #define Scale4Window               0.1
132 #define Scale4Iconic               0.07
133
134 #define one_third                  0.3333333333333333333
135
136 #define dirNone -1
137 #define dirUP 0
138 #define dirDOWN 1
139 #define dirLEFT 2
140 #define dirRIGHT 3
141 #define dirNEAR 4
142 #define dirFAR 5
143
144 #define HCELLS 33
145 #define VCELLS 25
146 #define DEFINEDCOLORS 7
147 #define elbowradius 0.5
148
149 /*************************************************************************/
150
151 typedef struct {
152         int         flip;
153
154         GLint       WindH, WindW;
155         int         Cells[HCELLS][VCELLS][HCELLS];
156         int         usedcolors[DEFINEDCOLORS];
157         int         directions[6];
158         int         ndirections;
159         int         nowdir, olddir;
160         int         system_number;
161         int         counter;
162         int         PX, PY, PZ;
163         int         number_of_systems;
164         int         system_type;
165         int         system_length;
166         int         turncounter;
167         Window      window;
168         const float *system_color;
169         GLfloat     initial_rotation;
170         GLuint      valve, bolts, betweenbolts, elbowbolts, elbowcoins;
171         GLuint      guagehead, guageface, guagedial, guageconnector, teapot;
172     int         teapot_polys;
173     int         reset;
174         GLXContext *glx_context;
175 } pipesstruct;
176
177 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
178 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
179 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
180
181 static const float front_shininess[] = {60.0};
182 static const float front_specular[] = {0.7, 0.7, 0.7, 1.0};
183 static const float ambient0[] = {0.4, 0.4, 0.4, 1.0};
184 static const float diffuse0[] = {1.0, 1.0, 1.0, 1.0};
185 static const float ambient1[] = {0.2, 0.2, 0.2, 1.0};
186 static const float diffuse1[] = {0.5, 0.5, 0.5, 1.0};
187 static const float position0[] = {1.0, 1.0, 1.0, 0.0};
188 static const float position1[] = {-1.0, -1.0, 1.0, 0.0};
189 static const float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0};
190 static const float lmodel_twoside[] = {GL_TRUE};
191
192 static const float MaterialRed[] = {0.7, 0.0, 0.0, 1.0};
193 static const float MaterialGreen[] = {0.1, 0.5, 0.2, 1.0};
194 static const float MaterialBlue[] = {0.0, 0.0, 0.7, 1.0};
195 static const float MaterialCyan[] = {0.2, 0.5, 0.7, 1.0};
196 static const float MaterialYellow[] = {0.7, 0.7, 0.0, 1.0};
197 static const float MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};
198 static const float MaterialWhite[] = {0.7, 0.7, 0.7, 1.0};
199 static const float MaterialGray[] = {0.2, 0.2, 0.2, 1.0};
200
201 static pipesstruct *pipes = NULL;
202
203
204 static void
205 MakeTube(ModeInfo *mi, int direction)
206 {
207         float       an;
208         float       SINan_3, COSan_3;
209
210         /*dirUP    = 00000000 */
211         /*dirDOWN  = 00000001 */
212         /*dirLEFT  = 00000010 */
213         /*dirRIGHT = 00000011 */
214         /*dirNEAR  = 00000100 */
215         /*dirFAR   = 00000101 */
216
217         if (!(direction & 4)) {
218                 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
219                           (direction & 2) ? 1.0 : 0.0, 0.0);
220         }
221         glBegin(GL_QUAD_STRIP);
222         for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
223                 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
224                 glVertex3f(COSan_3, SINan_3, one_third);
225                 glVertex3f(COSan_3, SINan_3, -one_third);
226         mi->polygon_count++;
227         }
228         glEnd();
229 }
230
231 static void
232 mySphere(float radius, Bool wire)
233 {
234 #if 0
235         GLUquadricObj *quadObj;
236
237         quadObj = gluNewQuadric();
238         gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
239         gluSphere(quadObj, radius, 16, 16);
240         gluDeleteQuadric(quadObj);
241 #else
242     glPushMatrix();
243     glScalef (radius, radius, radius);
244     glRotatef (90, 1, 0, 0);
245     unit_sphere (16, 16, wire);
246     glPopMatrix();
247 #endif
248 }
249
250 static void
251 myElbow(ModeInfo * mi, int bolted)
252 {
253 #define nsides 25
254 #define rings 25
255 #define r one_third
256 #define R one_third
257
258         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
259
260         int         i, j;
261         GLfloat     p0[3], p1[3], p2[3], p3[3];
262         GLfloat     n0[3], n1[3], n2[3], n3[3];
263         GLfloat     COSphi, COSphi1, COStheta, COStheta1;
264         GLfloat     _SINtheta, _SINtheta1;
265
266         for (i = 0; i <= rings / 4; i++) {
267                 GLfloat     theta, theta1;
268
269                 theta = (GLfloat) i *2.0 * M_PI / rings;
270
271                 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
272                 for (j = 0; j < nsides; j++) {
273                         GLfloat     phi, phi1;
274
275                         phi = (GLfloat) j *2.0 * M_PI / nsides;
276
277                         phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
278
279                         p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
280                         p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
281
282                         p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
283                         p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
284
285                         p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
286                         p2[1] = _SINtheta1 * (R + r * COSphi1);
287
288                         p3[0] = COStheta * (R + r * COSphi1);
289                         p3[1] = _SINtheta * (R + r * COSphi1);
290
291                         n0[0] = COStheta * COSphi;
292                         n0[1] = _SINtheta * COSphi;
293
294                         n1[0] = COStheta1 * COSphi;
295                         n1[1] = _SINtheta1 * COSphi;
296
297                         n2[0] = COStheta1 * COSphi1;
298                         n2[1] = _SINtheta1 * COSphi1;
299
300                         n3[0] = COStheta * COSphi1;
301                         n3[1] = _SINtheta * COSphi1;
302
303                         p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
304                         p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
305
306                         glBegin(GL_QUADS);
307                         glNormal3fv(n3);
308                         glVertex3fv(p3);
309                         glNormal3fv(n2);
310                         glVertex3fv(p2);
311                         glNormal3fv(n1);
312                         glVertex3fv(p1);
313                         glNormal3fv(n0);
314                         glVertex3fv(p0);
315             mi->polygon_count++;
316                         glEnd();
317                 }
318         }
319
320         if (factory > 0 && bolted) {
321                 /* Bolt the elbow onto the pipe system */
322                 glFrontFace(GL_CW);
323                 glPushMatrix();
324                 glRotatef(90.0, 0.0, 0.0, -1.0);
325                 glRotatef(90.0, 0.0, 1.0, 0.0);
326                 glTranslatef(0.0, one_third, one_third);
327                 glCallList(pp->elbowcoins);
328         mi->polygon_count += LWO_ElbowCoins.num_pnts/3;
329                 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
330                 glCallList(pp->elbowbolts);
331         mi->polygon_count += LWO_ElbowBolts.num_pnts/3;
332                 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
333                 glPopMatrix();
334                 glFrontFace(GL_CCW);
335         }
336 #undef r
337 #undef R
338 #undef nsides
339 #undef rings
340 }
341
342 static void
343 FindNeighbors(ModeInfo * mi)
344 {
345         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
346
347         pp->ndirections = 0;
348         pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
349         pp->ndirections += pp->directions[dirUP];
350         pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
351         pp->ndirections += pp->directions[dirDOWN];
352         pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
353         pp->ndirections += pp->directions[dirLEFT];
354         pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
355         pp->ndirections += pp->directions[dirRIGHT];
356         pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
357         pp->ndirections += pp->directions[dirFAR];
358         pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
359         pp->ndirections += pp->directions[dirNEAR];
360 }
361
362 static int
363 SelectNeighbor(ModeInfo * mi)
364 {
365         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
366         int         dirlist[6];
367         int         i, j;
368
369         for (i = 0, j = 0; i < 6; i++) {
370                 if (pp->directions[i]) {
371                         dirlist[j] = i;
372                         j++;
373                 }
374         }
375
376         return dirlist[NRAND(pp->ndirections)];
377 }
378
379 static void
380 MakeValve(ModeInfo * mi, int newdir)
381 {
382         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
383
384         /* There is a glPopMatrix() right after this subroutine returns. */
385         switch (newdir) {
386                 case dirUP:
387                 case dirDOWN:
388                         glRotatef(90.0, 1.0, 0.0, 0.0);
389                         glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
390                         break;
391                 case dirLEFT:
392                 case dirRIGHT:
393                         glRotatef(90.0, 0.0, -1.0, 0.0);
394                         glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
395                         break;
396                 case dirNEAR:
397                 case dirFAR:
398                         glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
399                         break;
400         }
401         glFrontFace(GL_CW);
402         glCallList(pp->betweenbolts);
403     mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
404         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
405         glCallList(pp->bolts);
406     mi->polygon_count += LWO_Bolts3D.num_pnts/3;
407         if (!MI_IS_MONO(mi)) {
408                 if (pp->system_color == MaterialRed) {
409                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
410                 } else if (pp->system_color == MaterialBlue) {
411                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
412                 } else if (pp->system_color == MaterialYellow) {
413                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
414                 } else {
415                         switch ((NRAND(3))) {
416                                 case 0:
417                                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
418                                         break;
419                                 case 1:
420                                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
421                                         break;
422                                 case 2:
423                                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
424                         }
425                 }
426         }
427         glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
428         glCallList(pp->valve);
429     mi->polygon_count += LWO_BigValve.num_pnts/3;
430         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
431         glFrontFace(GL_CCW);
432 }
433
434 static int
435 MakeGuage(ModeInfo * mi, int newdir)
436 {
437         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
438
439         /* Can't have a guage on a vertical pipe. */
440         if ((newdir == dirUP) || (newdir == dirDOWN))
441                 return (0);
442
443         /* Is there space above this pipe for a guage? */
444         if (!pp->directions[dirUP])
445                 return (0);
446
447         /* Yes!  Mark the space as used. */
448         pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
449
450         glFrontFace(GL_CW);
451         glPushMatrix();
452         if ((newdir == dirLEFT) || (newdir == dirRIGHT))
453                 glRotatef(90.0, 0.0, 1.0, 0.0);
454         glCallList(pp->betweenbolts);
455     mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
456         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
457         glCallList(pp->bolts);
458     mi->polygon_count += LWO_Bolts3D.num_pnts/3;
459         glPopMatrix();
460
461         glCallList(pp->guageconnector);
462     mi->polygon_count += LWO_GuageConnector.num_pnts/3;
463         glPushMatrix();
464         glTranslatef(0.0, 1.33333, 0.0);
465         /* Do not change the above to 1 + ONE_THIRD, because */
466         /* the object really is centered on 1.3333300000. */
467         glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
468         /* Random rotation for the dial.  I love it. */
469         glCallList(pp->guagedial);
470     mi->polygon_count += LWO_GuageDial.num_pnts/3;
471         glPopMatrix();
472
473         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
474         glCallList(pp->guagehead);
475     mi->polygon_count += LWO_GuageHead.num_pnts/3;
476
477         /* GuageFace is drawn last, in case of low-res depth buffers. */
478         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
479         glCallList(pp->guageface);
480     mi->polygon_count += LWO_GuageFace.num_pnts/3;
481
482         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
483         glFrontFace(GL_CCW);
484
485         return (1);
486 }
487
488
489 static GLuint
490 build_teapot(ModeInfo *mi)
491 {
492   pipesstruct *pp = &pipes[MI_SCREEN(mi)];
493   GLuint list = glGenLists(1);
494   if (!list) return 0;
495   glNewList(list, GL_COMPILE);
496   pp->teapot_polys = unit_teapot (12, MI_IS_WIREFRAME(mi));
497   glEndList();
498   return list;
499 }
500
501
502 static void
503 MakeTeapot(ModeInfo * mi, int newdir)
504 {
505   pipesstruct *pp = &pipes[MI_SCREEN(mi)];
506
507   switch (newdir) {
508   case dirUP:
509   case dirDOWN:
510     glRotatef(90.0, 1.0, 0.0, 0.0);
511     glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
512     break;
513   case dirLEFT:
514   case dirRIGHT:
515     glRotatef(90.0, 0.0, -1.0, 0.0);
516     glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
517     break;
518   case dirNEAR:
519   case dirFAR:
520     glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
521     break;
522   }
523
524   glCallList(pp->teapot);
525   mi->polygon_count += pp->teapot_polys;
526   glFrontFace(GL_CCW);
527 }
528
529
530 static void
531 MakeShape(ModeInfo * mi, int newdir)
532 {
533   int n = NRAND(100);
534   if (n < 50) {
535     if (!MakeGuage(mi, newdir))
536       MakeTube(mi, newdir);
537   } else if (n < 98) {
538     MakeValve(mi, newdir);
539   } else {
540     MakeTeapot(mi,newdir);
541   }
542 }
543
544 static void
545 pinit(ModeInfo * mi, int zera)
546 {
547         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
548         int         X, Y, Z;
549
550     if (zera)
551       mi->polygon_count = 0;
552
553         glClearDepth(1.0);
554         glColor3f(1.0, 1.0, 1.0);
555
556         glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
557         glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
558         glLightfv(GL_LIGHT0, GL_POSITION, position0);
559         glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
560         glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
561         glLightfv(GL_LIGHT1, GL_POSITION, position1);
562         glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
563         glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
564         glEnable(GL_LIGHTING);
565         glEnable(GL_LIGHT0);
566         glEnable(GL_LIGHT1);
567         glEnable(GL_DEPTH_TEST);
568         glEnable(GL_NORMALIZE);
569         glEnable(GL_CULL_FACE);
570
571         glShadeModel(GL_SMOOTH);
572         glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
573         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
574
575         if (zera) {
576                 pp->system_number = 1;
577                 glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
578                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
579                 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
580                 for (X = 0; X < HCELLS; X++) {
581                         for (Y = 0; Y < VCELLS; Y++) {
582                                 pp->Cells[X][Y][0] = 1;
583                                 pp->Cells[X][Y][HCELLS - 1] = 1;
584                                 pp->Cells[0][Y][X] = 1;
585                                 pp->Cells[HCELLS - 1][Y][X] = 1;
586                         }
587                 }
588                 for (X = 0; X < HCELLS; X++) {
589                         for (Z = 0; Z < HCELLS; Z++) {
590                                 pp->Cells[X][0][Z] = 1;
591                                 pp->Cells[X][VCELLS - 1][Z] = 1;
592                         }
593                 }
594                 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
595                 if ((pp->initial_rotation += 10.0) > 45.0) {
596                         pp->initial_rotation -= 90.0;
597                 }
598         }
599         pp->counter = 0;
600         pp->turncounter = 0;
601
602         if (!MI_IS_MONO(mi)) {
603                 int         collist[DEFINEDCOLORS];
604                 int         i, j, lower = 1000;
605
606                 /* Avoid repeating colors on the same screen unless necessary */
607                 for (i = 0; i < DEFINEDCOLORS; i++) {
608                         if (lower > pp->usedcolors[i])
609                                 lower = pp->usedcolors[i];
610                 }
611                 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
612                         if (pp->usedcolors[i] == lower) {
613                                 collist[j] = i;
614                                 j++;
615                         }
616                 }
617                 i = collist[NRAND(j)];
618                 pp->usedcolors[i]++;
619                 switch (i) {
620                         case 0:
621                                 pp->system_color = MaterialRed;
622                                 break;
623                         case 1:
624                                 pp->system_color = MaterialGreen;
625                                 break;
626                         case 2:
627                                 pp->system_color = MaterialBlue;
628                                 break;
629                         case 3:
630                                 pp->system_color = MaterialCyan;
631                                 break;
632                         case 4:
633                                 pp->system_color = MaterialYellow;
634                                 break;
635                         case 5:
636                                 pp->system_color = MaterialMagenta;
637                                 break;
638                         case 6:
639                                 pp->system_color = MaterialWhite;
640                                 break;
641                 }
642         } else {
643                 pp->system_color = MaterialGray;
644         }
645
646         do {
647                 pp->PX = NRAND((HCELLS - 1)) + 1;
648                 pp->PY = NRAND((VCELLS - 1)) + 1;
649                 pp->PZ = NRAND((HCELLS - 1)) + 1;
650         } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
651                  (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
652                   pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
653                   pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
654         pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
655         pp->olddir = dirNone;
656
657         FindNeighbors(mi);
658
659         pp->nowdir = SelectNeighbor(mi);
660 }
661
662 ENTRYPOINT void
663 reshape_pipes(ModeInfo * mi, int width, int height)
664 {
665         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
666     pinit(mi, 1);
667
668         glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
669         glMatrixMode(GL_PROJECTION);
670         glLoadIdentity();
671         /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
672         gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
673         glMatrixMode(GL_MODELVIEW);
674
675   glClear(GL_COLOR_BUFFER_BIT);
676 }
677
678 ENTRYPOINT void
679 init_pipes (ModeInfo * mi)
680 {
681         int         screen = MI_SCREEN(mi);
682         pipesstruct *pp;
683
684         if (pipes == NULL) {
685                 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
686                                               sizeof (pipesstruct))) == NULL)
687                         return;
688         }
689         pp = &pipes[screen];
690
691 #ifdef HAVE_JWZGLES
692     /* Single-buffering on iOS is so confusing! */
693     dbuf_p = True;
694 #endif
695
696         pp->window = MI_WINDOW(mi);
697         if ((pp->glx_context = init_GL(mi)) != NULL) {
698
699                 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
700                 if (rotatepipes)
701                   pp->initial_rotation = NRAND(180); /* jwz */
702                 else
703                   pp->initial_rotation = -10.0;
704                 pinit(mi, 1);
705
706                 if (factory > 0) {
707                         pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
708                         pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
709                         pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
710
711                         pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
712                         pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
713
714                         pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
715                         pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
716                         pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
717                         pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
718                         pp->teapot = build_teapot(mi);
719                 }
720                 /* else they are all 0, thanks to calloc(). */
721
722                 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
723                         pp->system_type = NRAND(NofSysTypes) + 1;
724                 } else {
725                         pp->system_type = MI_COUNT(mi);
726                 }
727
728                 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
729                         pp->number_of_systems = MI_CYCLES(mi);
730                 } else {
731                         pp->number_of_systems = 5;
732                 }
733
734                 if (MI_SIZE(mi) < 10) {
735                         pp->system_length = 10;
736                 } else if (MI_SIZE(mi) > 1000) {
737                         pp->system_length = 1000;
738                 } else {
739                         pp->system_length = MI_SIZE(mi);
740                 }
741         } else {
742                 MI_CLEARWINDOW(mi);
743         }
744 }
745
746 ENTRYPOINT void
747 draw_pipes (ModeInfo * mi)
748 {
749         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
750
751         Display    *display = MI_DISPLAY(mi);
752         Window      window = MI_WINDOW(mi);
753     Bool        wire = MI_IS_WIREFRAME(mi);
754
755         int         newdir;
756         int         OPX, OPY, OPZ;
757
758         if (!pp->glx_context)
759                 return;
760
761         glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
762
763     if (pp->reset) {
764       if (--pp->reset) {
765         /* Would be nice to fade to black here, by drawing successive quads
766            over the whole scene with gamma. */
767         return;
768       }
769       pinit(mi, 1);
770     }
771
772         glPushMatrix();
773
774         glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
775         if (rotatepipes)
776                 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
777
778         if (!MI_IS_ICONIC(mi)) {
779                 /* Width/height ratio handled by gluPerspective() now. */
780                 glScalef(Scale4Window, Scale4Window, Scale4Window);
781         } else {
782                 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
783         }
784
785         FindNeighbors(mi);
786
787         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
788
789         /* If it's the begining of a system, draw a sphere */
790         if (pp->olddir == dirNone) {
791                 glPushMatrix();
792                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
793                 mySphere(0.6, wire);
794                 glPopMatrix();
795         }
796         /* Check for stop conditions */
797         if (pp->ndirections == 0 || pp->counter > pp->system_length) {
798                 glPushMatrix();
799                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
800                 /* Finish the system with another sphere */
801                 mySphere(0.6, wire);
802
803                 glPopMatrix();
804
805                 /* If the maximum number of system was drawn, restart (clearing the screen), */
806                 /* else start a new system. */
807                 if (++pp->system_number > pp->number_of_systems) {
808           /* pause doing nothing for N seconds before clearing the screen. */
809           int secs = 3;
810           pp->reset = secs * 1000000 / (MI_PAUSE(mi) ? MI_PAUSE(mi) : 100);
811                 } else {
812                         pinit(mi, 0);
813                 }
814
815                 glPopMatrix();
816                 return;
817         }
818         pp->counter++;
819         pp->turncounter++;
820
821         /* Do will the direction change? if so, determine the new one */
822         newdir = pp->nowdir;
823         if (!pp->directions[newdir]) {  /* cannot proceed in the current direction */
824                 newdir = SelectNeighbor(mi);
825         } else {
826                 if (tightturns) {
827                         /* random change (20% chance) */
828                         if ((pp->counter > 1) && (NRAND(100) < 20)) {
829                                 newdir = SelectNeighbor(mi);
830                         }
831                 } else {
832                         /* Chance to turn increases after each length of pipe drawn */
833                         if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
834                                 newdir = SelectNeighbor(mi);
835                                 pp->turncounter = 0;
836                         }
837                 }
838         }
839
840         /* Has the direction changed? */
841         if (newdir == pp->nowdir) {
842                 /* If not, draw the cell's center pipe */
843                 glPushMatrix();
844                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
845                 /* Chance of factory shape here, if enabled. */
846                 if ((pp->counter > 1) && (NRAND(100) < factory)) {
847                         MakeShape(mi, newdir);
848                 } else {
849                         MakeTube(mi, newdir);
850                 }
851                 glPopMatrix();
852         } else {
853                 /* If so, draw the cell's center elbow/sphere */
854                 int         sysT = pp->system_type;
855
856                 if (sysT == NofSysTypes + 1) {
857                         sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
858                 }
859                 glPushMatrix();
860
861                 switch (sysT) {
862                         case 1:
863                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
864                                 mySphere(elbowradius, wire);
865                                 break;
866                         case 2:
867                         case 3:
868                                 switch (pp->nowdir) {
869                                         case dirUP:
870                                                 switch (newdir) {
871                                                         case dirLEFT:
872                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
873                                                                 glRotatef(180.0, 1.0, 0.0, 0.0);
874                                                                 break;
875                                                         case dirRIGHT:
876                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
877                                                                 glRotatef(180.0, 1.0, 0.0, 0.0);
878                                                                 glRotatef(180.0, 0.0, 1.0, 0.0);
879                                                                 break;
880                                                         case dirFAR:
881                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
882                                                                 glRotatef(90.0, 0.0, 1.0, 0.0);
883                                                                 glRotatef(180.0, 0.0, 0.0, 1.0);
884                                                                 break;
885                                                         case dirNEAR:
886                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
887                                                                 glRotatef(90.0, 0.0, 1.0, 0.0);
888                                                                 glRotatef(180.0, 1.0, 0.0, 0.0);
889                                                                 break;
890                                                 }
891                                                 break;
892                                         case dirDOWN:
893                                                 switch (newdir) {
894                                                         case dirLEFT:
895                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
896                                                                 break;
897                                                         case dirRIGHT:
898                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
899                                                                 glRotatef(180.0, 0.0, 1.0, 0.0);
900                                                                 break;
901                                                         case dirFAR:
902                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
903                                                                 glRotatef(270.0, 0.0, 1.0, 0.0);
904                                                                 break;
905                                                         case dirNEAR:
906                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
907                                                                 glRotatef(90.0, 0.0, 1.0, 0.0);
908                                                                 break;
909                                                 }
910                                                 break;
911                                         case dirLEFT:
912                                                 switch (newdir) {
913                                                         case dirUP:
914                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
915                                                                 glRotatef(180.0, 0.0, 1.0, 0.0);
916                                                                 break;
917                                                         case dirDOWN:
918                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
919                                                                 glRotatef(180.0, 1.0, 0.0, 0.0);
920                                                                 glRotatef(180.0, 0.0, 1.0, 0.0);
921                                                                 break;
922                                                         case dirFAR:
923                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
924                                                                 glRotatef(270.0, 1.0, 0.0, 0.0);
925                                                                 glRotatef(180.0, 0.0, 1.0, 0.0);
926                                                                 break;
927                                                         case dirNEAR:
928                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
929                                                                 glRotatef(270.0, 1.0, 0.0, 0.0);
930                                                                 glRotatef(180.0, 0.0, 0.0, 1.0);
931                                                                 break;
932                                                 }
933                                                 break;
934                                         case dirRIGHT:
935                                                 switch (newdir) {
936                                                         case dirUP:
937                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
938                                                                 break;
939                                                         case dirDOWN:
940                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
941                                                                 glRotatef(180.0, 1.0, 0.0, 0.0);
942                                                                 break;
943                                                         case dirFAR:
944                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
945                                                                 glRotatef(270.0, 1.0, 0.0, 0.0);
946                                                                 break;
947                                                         case dirNEAR:
948                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
949                                                                 glRotatef(90.0, 1.0, 0.0, 0.0);
950                                                                 break;
951                                                 }
952                                                 break;
953                                         case dirNEAR:
954                                                 switch (newdir) {
955                                                         case dirLEFT:
956                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
957                                                                 glRotatef(270.0, 1.0, 0.0, 0.0);
958                                                                 break;
959                                                         case dirRIGHT:
960                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
961                                                                 glRotatef(270.0, 1.0, 0.0, 0.0);
962                                                                 glRotatef(180.0, 0.0, 1.0, 0.0);
963                                                                 break;
964                                                         case dirUP:
965                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
966                                                                 glRotatef(270.0, 0.0, 1.0, 0.0);
967                                                                 break;
968                                                         case dirDOWN:
969                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
970                                                                 glRotatef(90.0, 0.0, 1.0, 0.0);
971                                                                 glRotatef(180.0, 0.0, 0.0, 1.0);
972                                                                 break;
973                                                 }
974                                                 break;
975                                         case dirFAR:
976                                                 switch (newdir) {
977                                                         case dirUP:
978                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
979                                                                 glRotatef(90.0, 0.0, 1.0, 0.0);
980                                                                 break;
981                                                         case dirDOWN:
982                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
983                                                                 glRotatef(90.0, 0.0, 1.0, 0.0);
984                                                                 glRotatef(180.0, 1.0, 0.0, 0.0);
985                                                                 break;
986                                                         case dirLEFT:
987                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
988                                                                 glRotatef(90.0, 1.0, 0.0, 0.0);
989                                                                 break;
990                                                         case dirRIGHT:
991                                                                 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
992                                                                 glRotatef(270.0, 1.0, 0.0, 0.0);
993                                                                 glRotatef(180.0, 0.0, 0.0, 1.0);
994                                                                 break;
995                                                 }
996                                                 break;
997                                 }
998                                 myElbow(mi, (sysT == 2));
999                                 break;
1000                 }
1001                 glPopMatrix();
1002         }
1003
1004         OPX = pp->PX;
1005         OPY = pp->PY;
1006         OPZ = pp->PZ;
1007         pp->olddir = pp->nowdir;
1008         pp->nowdir = newdir;
1009         switch (pp->nowdir) {
1010                 case dirUP:
1011                         pp->PY++;
1012                         break;
1013                 case dirDOWN:
1014                         pp->PY--;
1015                         break;
1016                 case dirLEFT:
1017                         pp->PX--;
1018                         break;
1019                 case dirRIGHT:
1020                         pp->PX++;
1021                         break;
1022                 case dirNEAR:
1023                         pp->PZ++;
1024                         break;
1025                 case dirFAR:
1026                         pp->PZ--;
1027                         break;
1028         }
1029         pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
1030
1031         /* Cells'face pipe */
1032         glTranslatef(((pp->PX + OPX) / 2.0 - 16) / 3.0 * 4.0, ((pp->PY + OPY) / 2.0 - 12) / 3.0 * 4.0, ((pp->PZ + OPZ) / 2.0 - 16) / 3.0 * 4.0);
1033         MakeTube(mi, newdir);
1034
1035         glPopMatrix();
1036
1037         glFlush();
1038
1039     if (mi->fps_p) do_fps (mi);
1040
1041     if (dbuf_p)
1042       glXSwapBuffers(display, window);
1043 }
1044
1045 #ifndef STANDALONE
1046 ENTRYPOINT void
1047 change_pipes (ModeInfo * mi)
1048 {
1049         pipesstruct *pp = &pipes[MI_SCREEN(mi)];
1050
1051         if (!pp->glx_context)
1052                 return;
1053
1054         glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
1055         pinit(mi, 1);
1056 }
1057 #endif /* !STANDALONE */
1058
1059
1060 ENTRYPOINT void
1061 release_pipes (ModeInfo * mi)
1062 {
1063         if (pipes != NULL) {
1064                 int         screen;
1065
1066                 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
1067                         pipesstruct *pp = &pipes[screen];
1068
1069                         if (pp->glx_context) {
1070
1071                                 /* Display lists MUST be freed while their glXContext is current. */
1072                                 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
1073
1074                                 if (pp->valve)
1075                                         glDeleteLists(pp->valve, 1);
1076                                 if (pp->bolts)
1077                                         glDeleteLists(pp->bolts, 1);
1078                                 if (pp->betweenbolts)
1079                                         glDeleteLists(pp->betweenbolts, 1);
1080
1081                                 if (pp->elbowbolts)
1082                                         glDeleteLists(pp->elbowbolts, 1);
1083                                 if (pp->elbowcoins)
1084                                         glDeleteLists(pp->elbowcoins, 1);
1085
1086                                 if (pp->guagehead)
1087                                         glDeleteLists(pp->guagehead, 1);
1088                                 if (pp->guageface)
1089                                         glDeleteLists(pp->guageface, 1);
1090                                 if (pp->guagedial)
1091                                         glDeleteLists(pp->guagedial, 1);
1092                                 if (pp->guageconnector)
1093                                         glDeleteLists(pp->guageconnector, 1);
1094                                 if (pp->teapot)
1095                                         glDeleteLists(pp->teapot, 1);
1096                         }
1097                 }
1098
1099                 (void) free((void *) pipes);
1100                 pipes = NULL;
1101         }
1102         FreeAllGL(mi);
1103 }
1104
1105 XSCREENSAVER_MODULE ("Pipes", pipes)
1106
1107 #endif