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