29e6f23d3cc69f4ba0bf12e3cbf66f2e5e8e6017
[xscreensaver] / hacks / glx / glblur.c
1 /* glblur --- radial blur using GL textures
2  * Copyright (c) 2002-2004 Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  *
12  * This program draws a box and a few line segments, and generates a flowing
13  * radial blur outward from it -- this causes flowing field effects.
14  * It does this by rendering the scene into a small texture, then repeatedly
15  * rendering increasingly-enlarged and increasingly-transparent versions of
16  * that texture onto the frame buffer.
17  *
18  * As such, it's quite graphics intensive -- don't bother trying to run this
19  * if you don't have hardware-accelerated texture support.
20  *
21  * Inspired by Dario Corno's Radial Blur tutorial:
22  *    http://nehe.gamedev.net/tutorials/lesson.asp?l=36
23  */
24
25 #include <X11/Intrinsic.h>
26
27 extern XtAppContext app;
28
29 #define PROGCLASS       "GLBlur"
30 #define HACK_INIT       init_glblur
31 #define HACK_DRAW       draw_glblur
32 #define HACK_RESHAPE    reshape_glblur
33 #define HACK_HANDLE_EVENT glblur_handle_event
34 #define EVENT_MASK      PointerMotionMask
35 #define sws_opts        xlockmore_opts
36
37 #define DEF_SPIN        "XYZ"
38 #define DEF_WANDER      "True"
39 #define DEF_BLURSIZE    "15"
40
41 #define DEFAULTS        "*delay:        10000       \n" \
42                         "*showFPS:      False       \n" \
43                         "*fpsSolid:     True        \n" \
44                         "*wireframe:    False       \n" \
45
46
47 #undef countof
48 #define countof(x) (sizeof((x))/sizeof((*x)))
49
50 #undef ABS
51 #define ABS(n) ((n)<0?-(n):(n))
52 #undef SIGNOF
53 #define SIGNOF(n) ((n)<0?-1:1)
54
55 #include "xlockmore.h"
56 #include "colors.h"
57 #include "rotator.h"
58 #include "gltrackball.h"
59 #include <ctype.h>
60
61 #ifdef USE_GL /* whole file */
62
63 #include <GL/glu.h>
64
65
66 typedef struct metaball metaball;
67
68
69 typedef struct {
70   GLXContext *glx_context;
71   rotator *rot;
72   trackball_state *trackball;
73   Bool button_down_p;
74
75   GLuint obj_dlist0;    /* east-west cube faces */
76   GLuint obj_dlist1;    /* north-south cube faces */
77   GLuint obj_dlist2;    /* up-down cube faces */
78   GLuint obj_dlist3;    /* spikes coming out of the cube's corners */
79   GLuint scene_dlist1;  /* the cube, rotated and translated */
80   GLuint scene_dlist2;  /* the spikes, rotated and translated */
81   int scene_polys1;     /* polygons in scene, not counting texture overlay */
82   int scene_polys2;     /* polygons in scene, not counting texture overlay */
83
84   GLuint texture;
85   unsigned int *tex_data;
86   int tex_w, tex_h;
87
88   int ncolors;
89   XColor *colors0;
90   XColor *colors1;
91   XColor *colors2;
92   XColor *colors3;
93   int ccolor;
94
95   Bool show_cube_p;
96   Bool show_spikes_p;
97
98 } glblur_configuration;
99
100 static glblur_configuration *bps = NULL;
101
102 static char *do_spin;
103 static Bool do_wander;
104 static int blursize;
105
106 static XrmOptionDescRec opts[] = {
107   { "-spin",   ".spin",   XrmoptionSepArg, 0 },
108   { "+spin",   ".spin",   XrmoptionNoArg, "" },
109   { "-blursize", ".blurSize", XrmoptionSepArg, 0 },
110   { "-wander", ".wander", XrmoptionNoArg, "True" },
111   { "+wander", ".wander", XrmoptionNoArg, "False" },
112 };
113
114 static argtype vars[] = {
115   {&do_spin,   "spin",   "Spin",   DEF_SPIN,   t_String},
116   {&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
117   {&blursize,  "blurSize","BlurSize", DEF_BLURSIZE,  t_Int},
118 };
119
120 ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
121
122
123 /* Window management, etc
124  */
125 void
126 reshape_glblur (ModeInfo *mi, int width, int height)
127 {
128   GLfloat h = (GLfloat) height / (GLfloat) width;
129
130   glViewport (0, 0, (GLint) width, (GLint) height);
131
132   glMatrixMode(GL_PROJECTION);
133   glLoadIdentity();
134   gluPerspective (30.0, 1/h, 1.0, 100.0);
135
136   glMatrixMode(GL_MODELVIEW);
137   glLoadIdentity();
138   gluLookAt( 0.0, 0.0, 8.0,
139              0.0, 0.0, 0.0,
140              0.0, 1.0, 0.0);
141
142   glClear(GL_COLOR_BUFFER_BIT);
143 }
144
145
146 \f
147 /* Objects in the scene 
148  */
149
150 static void
151 generate_object (ModeInfo *mi)
152 {
153   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
154   Bool wire = MI_IS_WIREFRAME (mi);
155   int s = 10;
156
157   bp->scene_polys1 = 0;
158   bp->scene_polys2 = 0;
159
160   glNewList (bp->obj_dlist0, GL_COMPILE);
161   glBegin (wire ? GL_LINE_LOOP : GL_QUADS);     /* front */
162   glNormal3f (0, 0, 1);
163   glTexCoord2f(1, 0); glVertex3f ( 0.5, -0.5,  0.5);
164   glTexCoord2f(0, 0); glVertex3f ( 0.5,  0.5,  0.5);
165   glTexCoord2f(0, 1); glVertex3f (-0.5,  0.5,  0.5);
166   glTexCoord2f(1, 1); glVertex3f (-0.5, -0.5,  0.5);
167   bp->scene_polys1++;
168   glEnd();
169
170   glBegin (wire ? GL_LINE_LOOP : GL_QUADS);     /* back */
171   glNormal3f (0, 0, -1);
172   glTexCoord2f(0, 0); glVertex3f (-0.5, -0.5, -0.5);
173   glTexCoord2f(0, 1); glVertex3f (-0.5,  0.5, -0.5);
174   glTexCoord2f(1, 1); glVertex3f ( 0.5,  0.5, -0.5);
175   glTexCoord2f(1, 0); glVertex3f ( 0.5, -0.5, -0.5);
176   bp->scene_polys1++;
177   glEnd();
178   glEndList();
179
180   glNewList (bp->obj_dlist1, GL_COMPILE);
181   glBegin (wire ? GL_LINE_LOOP : GL_QUADS);     /* left */
182   glNormal3f (-1, 0, 0);
183   glTexCoord2f(1, 1); glVertex3f (-0.5,  0.5,  0.5);
184   glTexCoord2f(1, 0); glVertex3f (-0.5,  0.5, -0.5);
185   glTexCoord2f(0, 0); glVertex3f (-0.5, -0.5, -0.5);
186   glTexCoord2f(0, 1); glVertex3f (-0.5, -0.5,  0.5);
187   bp->scene_polys1++;
188   glEnd();
189
190   glBegin (wire ? GL_LINE_LOOP : GL_QUADS);     /* right */
191   glNormal3f (1, 0, 0);
192   glTexCoord2f(1, 1); glVertex3f ( 0.5, -0.5, -0.5);
193   glTexCoord2f(1, 0); glVertex3f ( 0.5,  0.5, -0.5);
194   glTexCoord2f(0, 0); glVertex3f ( 0.5,  0.5,  0.5);
195   glTexCoord2f(0, 1); glVertex3f ( 0.5, -0.5,  0.5);
196   bp->scene_polys1++;
197   glEnd();
198   glEndList();
199
200   glNewList (bp->obj_dlist2, GL_COMPILE);
201   glBegin (wire ? GL_LINE_LOOP : GL_QUADS);     /* top */
202   glNormal3f (0, 1, 0);
203   glTexCoord2f(0, 0); glVertex3f ( 0.5,  0.5,  0.5);
204   glTexCoord2f(0, 1); glVertex3f ( 0.5,  0.5, -0.5);
205   glTexCoord2f(1, 1); glVertex3f (-0.5,  0.5, -0.5);
206   glTexCoord2f(1, 0); glVertex3f (-0.5,  0.5,  0.5);
207   bp->scene_polys1++;
208   glEnd();
209
210   glBegin (wire ? GL_LINE_LOOP : GL_QUADS);     /* bottom */
211   glNormal3f (0, -1, 0);
212   glTexCoord2f(1, 0); glVertex3f (-0.5, -0.5,  0.5);
213   glTexCoord2f(0, 0); glVertex3f (-0.5, -0.5, -0.5);
214   glTexCoord2f(0, 1); glVertex3f ( 0.5, -0.5, -0.5);
215   glTexCoord2f(1, 1); glVertex3f ( 0.5, -0.5,  0.5);
216   bp->scene_polys1++;
217   glEnd();
218   glEndList();
219
220   glNewList (bp->obj_dlist3, GL_COMPILE);
221   glLineWidth (1);
222   glBegin(GL_LINES);
223   glVertex3f(-s, 0, 0); glVertex3f(s, 0, 0);    /* face spikes */
224   glVertex3f(0, -s, 0); glVertex3f(0, s, 0);
225   glVertex3f(0, 0, -s); glVertex3f(0, 0, s);
226   bp->scene_polys2 += 3;
227   glEnd();
228
229   glLineWidth (8);
230   glBegin(GL_LINES);
231   glVertex3f(-s, -s, -s); glVertex3f( s,  s,  s);  /* corner spikes */
232   glVertex3f(-s, -s,  s); glVertex3f( s,  s, -s);
233   glVertex3f(-s,  s, -s); glVertex3f( s, -s,  s);
234   glVertex3f( s, -s, -s); glVertex3f(-s,  s,  s);
235   bp->scene_polys2 += 4;
236   glEnd();
237   glEndList ();
238
239   check_gl_error ("object generation");
240 }
241
242
243 static void
244 init_texture (ModeInfo *mi)
245 {
246   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
247
248   if (bp->tex_data) free (bp->tex_data);
249
250   bp->tex_w = 128;
251   bp->tex_h = 128;
252   bp->tex_data = (unsigned int *)
253     malloc (bp->tex_w * bp->tex_h * 4 * sizeof (unsigned int));
254
255   glGenTextures (1, &bp->texture);
256   glBindTexture (GL_TEXTURE_2D, bp->texture);
257   glTexImage2D (GL_TEXTURE_2D, 0, 4, 128, 128, 0,
258                 GL_RGBA,
259                 /* GL_UNSIGNED_BYTE, */
260                 GL_UNSIGNED_INT_8_8_8_8_REV,
261                 bp->tex_data);
262   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
263   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
264 }
265
266
267 static void
268 render_scene_to_texture (ModeInfo *mi)
269 {
270   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
271
272   glViewport (0, 0, bp->tex_w, bp->tex_h);
273
274   glCallList (bp->scene_dlist1);
275   glCallList (bp->scene_dlist2);
276
277   glBindTexture (GL_TEXTURE_2D, bp->texture);
278   glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0,
279                     bp->tex_w, bp->tex_h, 0);
280   check_gl_error ("texture");
281
282   glViewport (0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
283 }
284
285 static void
286 overlay_blur_texture (ModeInfo *mi)
287 {
288   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
289   int w = MI_WIDTH (mi);
290   int h = MI_HEIGHT (mi);
291   int times = blursize;
292   int i;
293   GLfloat inc = 0.02 * (25.0 / times);
294
295   GLfloat spost = 0;                /* starting texture coordinate offset */
296   GLfloat alpha_inc = 0.9 / times;  /* transparency fade factor */
297   GLfloat alpha = 0.2;              /* initial transparency */
298
299   glDisable (GL_TEXTURE_GEN_S);
300   glDisable (GL_TEXTURE_GEN_T);
301
302   glEnable (GL_TEXTURE_2D);
303   glDisable (GL_DEPTH_TEST);
304   glBlendFunc (GL_SRC_ALPHA,GL_ONE);
305   glEnable (GL_BLEND);
306   glBindTexture (GL_TEXTURE_2D, bp->texture);
307
308
309   /* switch to orthographic projection, saving both previous matrixes
310      on their respective stacks.
311    */
312   glMatrixMode (GL_PROJECTION);
313   glPushMatrix();
314   glLoadIdentity();
315   glOrtho (0, w, h, 0, -1, 1);
316   glMatrixMode (GL_MODELVIEW);
317   glPushMatrix();
318   glLoadIdentity();     
319
320
321   alpha_inc = alpha / times;
322
323   mi->polygon_count = bp->scene_polys1 + bp->scene_polys2;
324
325   glBegin (GL_QUADS);
326   for (i = 0; i < times; i++)
327     {
328       glColor4f (1, 1, 1, alpha);
329       glTexCoord2f (0+spost, 1-spost); glVertex2f (0, 0);
330       glTexCoord2f (0+spost, 0+spost); glVertex2f (0, h);
331       glTexCoord2f (1-spost, 0+spost); glVertex2f (w, h);
332       glTexCoord2f (1-spost, 1-spost); glVertex2f (w, 0);
333       spost += inc;
334       alpha -= alpha_inc;
335       mi->polygon_count++;
336     }
337   glEnd();
338
339   /* Switch back to perspective projection, restoring the saved matrixes
340    */
341   glMatrixMode (GL_PROJECTION);
342   glPopMatrix();
343   glMatrixMode (GL_MODELVIEW);
344   glPopMatrix();                
345
346   glEnable (GL_DEPTH_TEST);
347   glDisable (GL_BLEND);
348   glDisable (GL_TEXTURE_2D);
349   glBindTexture (GL_TEXTURE_2D, 0);
350 }
351
352
353 \f
354 /* Startup initialization
355  */
356
357 Bool
358 glblur_handle_event (ModeInfo *mi, XEvent *event)
359 {
360   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
361
362   if (event->xany.type == ButtonPress &&
363       event->xbutton.button == Button1)
364     {
365       bp->button_down_p = True;
366       gltrackball_start (bp->trackball,
367                          event->xbutton.x, event->xbutton.y,
368                          MI_WIDTH (mi), MI_HEIGHT (mi));
369       return True;
370     }
371   else if (event->xany.type == ButtonRelease &&
372            event->xbutton.button == Button1)
373     {
374       bp->button_down_p = False;
375       return True;
376     }
377   else if (event->xany.type == ButtonPress &&
378            (event->xbutton.button == Button4 ||
379             event->xbutton.button == Button5))
380     {
381       gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
382                               !!event->xbutton.state);
383       return True;
384     }
385   else if (event->xany.type == MotionNotify &&
386            bp->button_down_p)
387     {
388       gltrackball_track (bp->trackball,
389                          event->xmotion.x, event->xmotion.y,
390                          MI_WIDTH (mi), MI_HEIGHT (mi));
391       return True;
392     }
393
394   return False;
395 }
396
397
398 void 
399 init_glblur (ModeInfo *mi)
400 {
401   glblur_configuration *bp;
402   int wire = MI_IS_WIREFRAME(mi);
403
404   if (!bps) {
405     bps = (glblur_configuration *)
406       calloc (MI_NUM_SCREENS(mi), sizeof (glblur_configuration));
407     if (!bps) {
408       fprintf(stderr, "%s: out of memory\n", progname);
409       exit(1);
410     }
411   }
412
413   bp = &bps[MI_SCREEN(mi)];
414
415   bp->glx_context = init_GL(mi);
416
417   reshape_glblur (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
418
419   if (!wire)
420     {
421       GLfloat gamb[4]= {0.2, 0.2,  0.2, 1.0};
422       GLfloat pos[4] = {0.0, 5.0, 10.0, 1.0};
423       GLfloat amb[4] = {0.2, 0.2,  0.2, 1.0};
424       GLfloat dif[4] = {0.3, 0.3,  0.3, 1.0};
425       GLfloat spc[4] = {0.8, 0.8,  0.8, 1.0};
426       GLfloat shiny = 128;
427
428       glEnable(GL_LIGHTING);
429       glEnable(GL_LIGHT0);
430
431       glEnable(GL_DEPTH_TEST);
432       glEnable(GL_CULL_FACE);
433       glEnable(GL_NORMALIZE);
434       glShadeModel(GL_SMOOTH);
435
436       glLightModelfv (GL_LIGHT_MODEL_AMBIENT, gamb);
437
438       glLightfv(GL_LIGHT0, GL_POSITION, pos);
439       glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
440       glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
441       glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
442
443       glEnable(GL_LIGHTING);
444       glEnable(GL_LIGHT0);
445
446       glMateriali(GL_FRONT, GL_SHININESS, shiny);
447     }
448
449   {
450     Bool spinx=False, spiny=False, spinz=False;
451     double spin_speed   = 0.9;
452     double wander_speed = 0.06;
453
454     char *s = do_spin;
455     while (*s)
456       {
457         if      (*s == 'x' || *s == 'X') spinx = True;
458         else if (*s == 'y' || *s == 'Y') spiny = True;
459         else if (*s == 'z' || *s == 'Z') spinz = True;
460         else
461           {
462             fprintf (stderr,
463          "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n",
464                      progname, do_spin);
465             exit (1);
466           }
467         s++;
468       }
469
470     bp->rot = make_rotator (spinx ? spin_speed : 0,
471                             spiny ? spin_speed : 0,
472                             spinz ? spin_speed : 0,
473                             1.0,
474                             do_wander ? wander_speed : 0,
475                             False);
476     bp->trackball = gltrackball_init ();
477   }
478
479   if (blursize < 0) blursize = 0;
480   if (blursize > 200) blursize = 200;
481
482   bp->ncolors = 128;
483   bp->colors0 = (XColor *) calloc(bp->ncolors, sizeof(XColor));
484   bp->colors1 = (XColor *) calloc(bp->ncolors, sizeof(XColor));
485   bp->colors2 = (XColor *) calloc(bp->ncolors, sizeof(XColor));
486   bp->colors3 = (XColor *) calloc(bp->ncolors, sizeof(XColor));
487   make_smooth_colormap (0, 0, 0, bp->colors0, &bp->ncolors, False, 0, False);
488   make_smooth_colormap (0, 0, 0, bp->colors1, &bp->ncolors, False, 0, False);
489   make_smooth_colormap (0, 0, 0, bp->colors2, &bp->ncolors, False, 0, False);
490   make_smooth_colormap (0, 0, 0, bp->colors3, &bp->ncolors, False, 0, False);
491   bp->ccolor = 0;
492
493   bp->obj_dlist0   = glGenLists (1);
494   bp->obj_dlist1   = glGenLists (1);
495   bp->obj_dlist2   = glGenLists (1);
496   bp->obj_dlist3   = glGenLists (1);
497   bp->scene_dlist1 = glGenLists (1);
498   bp->scene_dlist2 = glGenLists (1);
499
500   init_texture (mi);
501   generate_object (mi);
502 }
503
504
505 /* Render one frame
506  */
507 void
508 draw_glblur (ModeInfo *mi)
509 {
510   glblur_configuration *bp = &bps[MI_SCREEN(mi)];
511   Display *dpy = MI_DISPLAY(mi);
512   Window window = MI_WINDOW(mi);
513
514   static GLfloat color0[4] = {0.0, 0.0, 0.0, 1.0};
515   static GLfloat color1[4] = {0.0, 0.0, 0.0, 1.0};
516   static GLfloat color2[4] = {0.0, 0.0, 0.0, 1.0};
517   static GLfloat color3[4] = {0.0, 0.0, 0.0, 1.0};
518   static GLfloat spec[4]   = {1.0, 1.0, 1.0, 1.0};
519
520   double rx, ry, rz;
521   double px, py, pz;
522   int extra_polys = 0;
523
524   if (!bp->glx_context)
525     return;
526
527   /* Decide what we're drawing
528    */
529   if (0 == (random() % 30))
530     {
531       bp->show_cube_p   = (0 == (random() % 10));
532       bp->show_spikes_p = (0 == (random() % 20));
533     }
534
535   /* Select new colors for the various objects
536    */
537   color0[0] = bp->colors0[bp->ccolor].red   / 65536.0;
538   color0[1] = bp->colors0[bp->ccolor].green / 65536.0;
539   color0[2] = bp->colors0[bp->ccolor].blue  / 65536.0;
540
541   color1[0] = bp->colors1[bp->ccolor].red   / 65536.0;
542   color1[1] = bp->colors1[bp->ccolor].green / 65536.0;
543   color1[2] = bp->colors1[bp->ccolor].blue  / 65536.0;
544
545   color2[0] = bp->colors2[bp->ccolor].red   / 65536.0;
546   color2[1] = bp->colors2[bp->ccolor].green / 65536.0;
547   color2[2] = bp->colors2[bp->ccolor].blue  / 65536.0;
548
549   color3[0] = bp->colors3[bp->ccolor].red   / 65536.0;
550   color3[1] = bp->colors3[bp->ccolor].green / 65536.0;
551   color3[2] = bp->colors3[bp->ccolor].blue  / 65536.0;
552
553   bp->ccolor++;
554   if (bp->ccolor >= bp->ncolors) bp->ccolor = 0;
555
556
557   get_position (bp->rot, &px, &py, &pz, !bp->button_down_p);
558   get_rotation (bp->rot, &rx, &ry, &rz, !bp->button_down_p);
559
560   px = (px - 0.5) * 2;
561   py = (py - 0.5) * 2;
562   pz = (pz - 0.5) * 8;
563   rx *= 360;
564   ry *= 360;
565   rz *= 360;
566
567   /* Generate scene_dlist1, which contains the box (not spikes),
568      rotated into position.
569    */
570   glNewList (bp->scene_dlist1, GL_COMPILE);
571   {
572     glMatrixMode (GL_MODELVIEW);
573     glPushMatrix ();
574     glTranslatef (px, py, pz);
575     gltrackball_rotate (bp->trackball);
576     glRotatef (rx, 1.0, 0.0, 0.0);
577     glRotatef (ry, 0.0, 1.0, 0.0);
578     glRotatef (rz, 0.0, 0.0, 1.0);
579
580     glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
581
582     glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color0);
583     glCallList (bp->obj_dlist0);
584
585     glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color1);
586     glCallList (bp->obj_dlist1);
587
588     glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color2);
589     glCallList (bp->obj_dlist2);
590
591     glPopMatrix ();
592   }
593   glEndList ();
594
595
596   /* Generate scene_dlist2, which contains the spikes (not box),
597      rotated into position.
598    */
599   glNewList (bp->scene_dlist2, GL_COMPILE);
600   {
601     glMatrixMode (GL_MODELVIEW);
602     glPushMatrix ();
603     glTranslatef (px, py, pz);
604     gltrackball_rotate (bp->trackball);
605     glRotatef (rx, 1.0, 0.0, 0.0);
606     glRotatef (ry, 0.0, 1.0, 0.0);
607     glRotatef (rz, 0.0, 0.0, 1.0);
608
609     glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color3);
610     glCallList (bp->obj_dlist3);
611
612     glPopMatrix ();
613   }
614   glEndList ();
615
616
617   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
618
619   render_scene_to_texture (mi);
620
621   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
622
623   if (bp->show_cube_p || bp->button_down_p)
624     {
625       glCallList (bp->scene_dlist1);
626       extra_polys += bp->scene_polys1;
627     }
628   if (bp->show_spikes_p || bp->button_down_p)
629     {
630       glCallList (bp->scene_dlist2);
631       extra_polys += bp->scene_polys2;
632     }
633
634   overlay_blur_texture (mi);
635   mi->polygon_count += extra_polys;
636
637   glFlush ();
638
639   if (mi->fps_p) do_fps (mi);
640   glFinish();
641
642   glXSwapBuffers(dpy, window);
643 }
644
645
646 #endif /* USE_GL */