- /* disable depth testing for the stars, so they don't obscure the planet */
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_POINT_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glBegin(GL_POINTS);
- for(i = 0 ; i < NUM_STARS ; i++)
- {
-/* size = ((random()%size_range[0])) * size_range[1]/2.; */
-/* glPointSize(size); */
- x = random() % width;
- y = random() % height;
- glVertex2f(x,y);
- }
- glEnd();
-
- /* return to original PROJECT and MODELVIEW */
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
-
-
- glEndList();
-
-}
-
-/* Initialization function for screen saver */
-static void
-pinit(ModeInfo * mi)
-{
- Bool wire = MI_IS_WIREFRAME(mi);
- planetstruct *gp = &planets[MI_SCREEN(mi)];
- int i, j;
- int stacks=STACKS, slices=SLICES;
- float radius=RADIUS;
-
- float drho, dtheta;
- float rho, theta;
- GLfloat vector[3];
- GLfloat ds, dt, t, s;;
-
- if (wire) {
- glEnable(GL_LINE_SMOOTH);
- do_texture = False;
- }
-
- /* turn on various options we like */
- if (do_texture)
- setup_texture(mi);
- if (do_light)
- setup_light();
-
- setup_face();
-
- if (do_stars) {
- glEnable(GL_POINT_SMOOTH);
- generate_stars(MI_WIDTH(mi), MI_HEIGHT(mi));
- }
-
-
- /*-
- * Generate a sphere with quadrilaterals.
- * Quad vertices are determined using a parametric sphere function.
- * For fun, you could generate practically any parameteric surface and
- * map an image onto it.
- */
-
- drho = M_PI / stacks;
- dtheta = 2.0 * M_PI / slices;
- ds = 1.0 / slices;
- dt = 1.0 / stacks;
-
-
- gp->platelist=glGenLists(1);
- glNewList(gp->platelist, GL_COMPILE);
-
- glColor3f(1,1,1);
- glBegin( wire ? GL_LINE_LOOP : GL_QUADS );
-
- t = 0.0;
- for(i=0; i<stacks; i++) {
- rho = i * drho;
- s = 0.0;
- for(j=0; j<slices; j++) {
- theta = j * dtheta;
-
-
- glTexCoord2f(s,t);
- ParametricSphere(theta, rho, vector);
- normalize(vector);
- glNormal3fv(vector);
- ParametricSphere(theta, rho, vector);
- glVertex3f( vector[0]*radius, vector[1]*radius, vector[2]*radius );
-
- glTexCoord2f(s,t+dt);
- ParametricSphere(theta, rho+drho, vector);
- normalize(vector);
- glNormal3fv(vector);
- ParametricSphere(theta, rho+drho, vector);
- glVertex3f( vector[0]*radius, vector[1]*radius, vector[2]*radius );
-
- glTexCoord2f(s+ds,t+dt);
- ParametricSphere(theta + dtheta, rho+drho, vector);
- normalize(vector);
- glNormal3fv(vector);
- ParametricSphere(theta + dtheta, rho+drho, vector);
- glVertex3f( vector[0]*radius, vector[1]*radius, vector[2]*radius );
-
- glTexCoord2f(s+ds, t);
- ParametricSphere(theta + dtheta, rho, vector);
- normalize(vector);
- glNormal3fv(vector);
- ParametricSphere(theta + dtheta, rho, vector);
- glVertex3f( vector[0]*radius, vector[1]*radius, vector[2]*radius );
-
- s = s + ds;
-
- }
- t = t + dt;
- }
- glEnd();
- glEndList();
-
-
- }
-
-static void
-draw_sphere(ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- glEnable(GL_DEPTH_TEST);
-
- /* turn on the various attributes for making the sphere look nice */
- if (do_texture)
- glEnable(GL_TEXTURE_2D);
-
- if (do_light)
- {
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- }
-
- glCallList(gp->platelist);
-
-}
-
-
-#define RANDSIGN() ((random() & 1) ? 1 : -1)
-
-static void
-pick_velocity (ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- gp->box_width = 15.0;
- gp->box_height = 15.0;
- gp->box_depth = 5.0;
-
- gp->tx = 0.0;
- gp->ty = 0.0;
- gp->tz = frand(360);
-
- gp->dtx = (frand(0.4) + frand(0.3)) * RANDSIGN();
- gp->dty = (frand(0.4) + frand(0.3)) * RANDSIGN();
- gp->dtz = (frand(5.0) + frand(5.0)); /* the sun sets in the west */
-
- gp->dx = (frand(0.2) + frand(0.2)) * RANDSIGN();
- gp->dy = (frand(0.2) + frand(0.2)) * RANDSIGN();
- gp->dz = (frand(0.2) + frand(0.2)) * RANDSIGN();