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