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