From http://www.jwz.org/xscreensaver/xscreensaver-5.16.tar.gz
[xscreensaver] / hacks / glx / bubble3d.c
index 52dbc33e03b29843084a62de9c331ee99141f839..9cd2afc4f43fab240b21b23317b666b5a7df4906 100644 (file)
@@ -47,6 +47,7 @@ typedef struct bubble {
        GLfloat    *nudge_angle_incr;   /* Amount by which we increase each nudge
                                         * angle in each frame.
                                         */
+       GLfloat    color[4];
 } bubble;
 
 /* Should be taken care of already... but just in case */
@@ -83,7 +84,7 @@ max(GLfloat a, GLfloat b)
 
 /* Create a new bubble. */
 void       *
-glb_bubble_new(GLfloat x, GLfloat y, GLfloat z, GLfloat scale,
+glb_bubble_new(glb_data *d, GLfloat x, GLfloat y, GLfloat z, GLfloat scale,
               GLfloat y_incr, GLfloat scale_incr)
 {
        int         i, j;
@@ -91,13 +92,25 @@ glb_bubble_new(GLfloat x, GLfloat y, GLfloat z, GLfloat scale,
        /* GLfloat axes [glb_config.nr_nudge_axes][3]; */
        GLfloat     axes[5][3]; /* HARD CODED for SunCC */
        int         nr_vertices;
-       glb_vertex *vertices = glb_sphere_get_vertices(&nr_vertices);
+       glb_vertex *vertices = glb_sphere_get_vertices(d, &nr_vertices);
 
        bubble     *b = (bubble *) malloc(sizeof *b);
 
        if (b == 0)
                return 0;
 
+       if (glb_config.bubble_colour[0] == -1.0) {
+               b->color[0] = ((float) (NRAND(100)) / 100.0);
+               b->color[1] = ((float) (NRAND(100)) / 100.0);
+               b->color[2] = ((float) (NRAND(100)) / 100.0);
+       } else {
+               b->color[0] = glb_config.bubble_colour[0];
+               b->color[1] = glb_config.bubble_colour[1];
+               b->color[2] = glb_config.bubble_colour[2];
+       }
+       b->color[3] = glb_config.bubble_colour[3];
+       
+
        b->contributions = (GLfloat *) malloc(sizeof (GLfloat) * nr_vertices *
                                              glb_config.nr_nudge_axes);
        if (b->contributions == 0) {
@@ -202,14 +215,14 @@ glb_bubble_step(void *bb)
 
 /* Draw a bubble. */
 void
-glb_bubble_draw(void *bb)
+glb_bubble_draw(glb_data *d, void *bb)
 {
        int         i, j;
        bubble     *b = (bubble *) bb;
        int         nr_vertices;
-       glb_vertex *vertices = glb_sphere_get_vertices(&nr_vertices);
+       glb_vertex *vertices = glb_sphere_get_vertices(d, &nr_vertices);
        int         nr_triangles;
-       glb_triangle *triangles = glb_sphere_get_triangles(&nr_triangles);
+       glb_triangle *triangles = glb_sphere_get_triangles(d, &nr_triangles);
        glb_vertex *new_vertices;
 
        new_vertices = (glb_vertex *) malloc(sizeof (glb_vertex) * nr_vertices);
@@ -239,7 +252,11 @@ glb_bubble_draw(void *bb)
        glScalef(b->scale, b->scale, b->scale);
 
        /* Draw the bubble. */
+    glFrontFace(GL_CW);
        glBegin(GL_TRIANGLES);
+
+       glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, b->color);
+
        for (i = 0; i < nr_triangles; ++i) {
                glNormal3fv(new_vertices[triangles[i][0]]);
                glVertex3fv(new_vertices[triangles[i][0]]);
@@ -251,6 +268,7 @@ glb_bubble_draw(void *bb)
        glEnd();
        glPopMatrix();
        (void) free((void *) new_vertices);
+    glb_config.polygon_count += nr_triangles;
 }
 
 /* Return y value. */