-void
-draw_stars (ModeInfo * mi)
-{
- int width = MI_WIDTH(mi);
- int height = MI_HEIGHT(mi);
-
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- /* Sadly, this causes a stall of the graphics pipeline (as would the
- equivalent calls to glGet*.) But there's no way around this, short
- of having each caller set up the specific display matrix we need
- here, which would kind of defeat the purpose of centralizing this
- code in one file.
- */
- glPushAttrib(GL_TRANSFORM_BIT | /* for matrix contents */
- GL_ENABLE_BIT | /* for various glDisable calls */
- GL_CURRENT_BIT | /* for glColor3f() */
- GL_LIST_BIT); /* for glListBase() */
- {
- check_gl_error ("glPushAttrib");
-
- /* disable lighting and texturing when drawing stars!
- (glPopAttrib() restores these.)
- */
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_LIGHTING);
- glDisable(GL_DEPTH_TEST);
-
- /* glPopAttrib() does not restore matrix changes, so we must
- push/pop the matrix stacks to be non-intrusive there.
- */
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- {
- check_gl_error ("glPushMatrix");
- glLoadIdentity();
-
- /* Each matrix mode has its own stack, so we need to push/pop
- them separately. */
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- {
- check_gl_error ("glPushMatrix");
- glLoadIdentity();
-
- gluOrtho2D (0, width, 0, height);
- check_gl_error ("gluOrtho2D");
-
- /* Draw the stars */
- glScalef (width, height, 1);
- glCallList(gp->starlist);
- check_gl_error ("drawing stars");
- }
- glPopMatrix();
- }
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-
- }
- /* clean up after our state changes */
- glPopAttrib();
- check_gl_error ("glPopAttrib");
-}
-
-
-
-/* Set up lighting */
-static void
-init_sun (ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- GLfloat lamb[4] = { 0.0, 0.0, 0.0, 1.0 };
- GLfloat ldif[4] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat spec[4] = { 1.0, 1.0, 1.0, 1.0 };
-
- GLfloat mamb[4] = { 0.5, 0.5, 0.5, 1.0 };
- GLfloat mdif[4] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat mpec[4] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat shiny = .4;
-
- gp->sunpos[0] = 1.00 - frand(2.00);
- gp->sunpos[1] = 0.25 - frand(0.50);
- gp->sunpos[2] = -1.00;
- gp->sunpos[3] = 0.00;
-
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
-
- glLightfv (GL_LIGHT0, GL_POSITION, gp->sunpos);
- glLightfv (GL_LIGHT0, GL_AMBIENT, lamb);
- glLightfv (GL_LIGHT0, GL_DIFFUSE, ldif);
- glLightfv (GL_LIGHT0, GL_SPECULAR, spec);
-
- glMaterialfv (GL_FRONT, GL_AMBIENT, mamb);
- glMaterialfv (GL_FRONT, GL_DIFFUSE, mdif);
- glMaterialfv (GL_FRONT, GL_SPECULAR, mpec);
- glMaterialf (GL_FRONT, GL_SHININESS, shiny);
-
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glShadeModel(GL_SMOOTH);
-
- check_gl_error("lighting");
-}
-
-
-#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();
-}
-
-
-static void
-rotate_and_move (ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- if (do_roll)
- {
- gp->tx += gp->dtx;
- while (gp->tx < 0) gp->tx += 360;
- while (gp->tx > 360) gp->tx -= 360;
-
- gp->ty += gp->dty;
- while (gp->ty < 0) gp->ty += 360;
- while (gp->ty > 360) gp->ty -= 360;
- }
-
- if (do_rotate)
- {
- gp->tz += gp->dtz;
- while (gp->tz < 0) gp->tz += 360;
- while (gp->tz > 360) gp->tz -= 360;
- }
-
- if (do_wander)
- {
- static int frame = 0;
-# define SINOID(SCALE,SIZE) \
- ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)
- gp->xpos = SINOID(0.031, gp->box_width);
- gp->ypos = SINOID(0.023, gp->box_height);
- gp->zpos = SINOID(0.017, gp->box_depth);
- frame++;
- }
-}
-
-
-void