void glschool_createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, int *fish_polys, int *box_polys, int wire) { int faces = 16; *box_polys = 0; *fish_polys = 0; *box_polys += glschool_createBBoxList(bbox, bboxList, wire); *box_polys = 0; *fish_polys = 0; *goalList = glGenLists(1); glNewList(*goalList, GL_COMPILE); glScalef (5, 5, 5); *box_polys += unit_sphere (10, 10, wire); glEndList(); *fishList = glGenLists(1); glNewList(*fishList, GL_COMPILE); *fish_polys += cone (0, 0, 0, 0, 0, 10, 2, 0, faces, True, (faces <= 3), /* cap */ wire); glTranslatef (0, 0, -0.3); glScalef (2, 2, 2); glRotatef (90, 1, 0, 0); if (faces > 3) *fish_polys += unit_sphere (faces, faces, wire); glEndList(); }
/* rip off of the builBlock() function creating the GL compilied pointer "block" but only creates two spheres. spheres are created with unit_sphere from spheres.h to allow wire frame */ static void buildBlobBlock(ModeInfo *mi) { int wire = MI_IS_WIREFRAME(mi); topBlockSTATE *tb = &tbs[MI_SCREEN(mi)]; tb->block=glGenLists(1); /* only one */ glNewList(tb->block,GL_COMPILE); glPushMatrix(); glScalef(1.4,1.4,1.4); unit_sphere (resolution/2,resolution, wire); glPopMatrix(); glTranslatef(0.0f,-2.0f,0.0f); glScalef(1.4,1.4,1.4); unit_sphere (resolution/2,resolution, wire); glEndList(); }
static void draw_axis (ModeInfo *mi) { GLfloat s; glDisable (GL_TEXTURE_2D); glDisable (GL_LIGHTING); glPushMatrix(); align_axis (mi, 0); glTranslatef (0.34, 0.39, -0.61); s = 0.96; glScalef (s, s, s); /* tighten up the enclosing sphere */ glColor3f (0.5, 0.5, 0); glRotatef (90, 1, 0, 0); /* unit_sphere is off by 90 */ glRotatef (9.5, 0, 1, 0); /* line up the time zones */ glFrontFace (GL_CCW); unit_sphere (12, 24, True); glBegin(GL_LINES); glVertex3f(0, -2, 0); glVertex3f(0, 2, 0); glEnd(); glPopMatrix(); }
static void sphere (GLfloat x, GLfloat y, GLfloat z, GLfloat diameter, Bool wire) { int stacks = (scale_down ? SPHERE_STACKS_2 : SPHERE_STACKS); int slices = (scale_down ? SPHERE_SLICES_2 : SPHERE_SLICES); glPushMatrix (); glTranslatef (x, y, z); glScalef (diameter, diameter, diameter); unit_sphere (stacks, slices, wire); glPopMatrix (); }
void createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, Bool wire) { createBBoxList(bbox, bboxList, wire); *goalList = glGenLists(1); glNewList(*goalList, GL_COMPILE); glScalef(10.0, 10.0, 10.0); unit_sphere(10, 10, wire); glEndList(); *fishList = glGenLists(1); glNewList(*fishList, GL_COMPILE); glScalef(2.0, 2.0, 2.0); unit_sphere(10, 10, wire); cone(0, 0, 0, 0, 0, 5, 1, 0, 10, True, False, wire); glEndList(); }
static int draw_sphere(int pos, int tick) { int pos2 = (pos+1) % NPOSITIONS; GLfloat x1 = ball_positions[pos*3]; GLfloat y1 = ball_positions[pos*3+1]; GLfloat z1 = ball_positions[pos*3+2]; GLfloat x2 = ball_positions[pos2*3]; GLfloat y2 = ball_positions[pos2*3+1]; GLfloat z2 = ball_positions[pos2*3+2]; GLfloat frac = tick / (GLfloat) SPHERE_TICKS; GLfloat x = x1 + (x2 - x1) * frac; GLfloat y = y1 + (y2 - y1) * frac + (2 * sin (M_PI * frac)); GLfloat z = z1 + (z2 - z1) * frac; int polys = 0; glPushMatrix(); # ifdef DEBUG_PATH glVertex3f(x, y, z); if (tick == 0) { glVertex3f(x, y-7.5, z); glVertex3f(x, y, z); glVertex3f(x, y, z-0.6); glVertex3f(x, y, z); glVertex3f(x, y, z+0.6); glVertex3f(x, y, z); glVertex3f(x+0.6, y, z); glVertex3f(x, y, z); glVertex3f(x-0.6, y, z); glVertex3f(x, y, z); } # else /* !DEBUG_PATH */ y += 0.5; glTranslatef(x, y, z); glScalef (0.5, 0.5, 0.5); /* make ball a little smaller on the gap to obscure distance */ if (pos == NPOSITIONS-1) glScalef (0.95, 0.95, 0.95); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow); glDisable (GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glFrontFace(GL_CCW); polys += unit_sphere (32, 32, False); glShadeModel(GL_FLAT); glEnable (GL_TEXTURE_2D); #endif /* !DEBUG_PATH */ glPopMatrix(); return polys; }
static int sphere (molecule_configuration *mc, GLfloat x, GLfloat y, GLfloat z, GLfloat diameter, Bool wire) { int stacks = (mc->scale_down ? SPHERE_STACKS_2 : SPHERE_STACKS); int slices = (mc->scale_down ? SPHERE_SLICES_2 : SPHERE_SLICES); glPushMatrix (); glTranslatef (x, y, z); glScalef (diameter, diameter, diameter); unit_sphere (stacks, slices, wire); glPopMatrix (); return stacks * slices; }
static void mySphere(float radius, Bool wire) { #if 0 GLUquadricObj *quadObj; quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL); gluSphere(quadObj, radius, 16, 16); gluDeleteQuadric(quadObj); #else glPushMatrix(); glScalef (radius, radius, radius); glRotatef (90, 1, 0, 0); unit_sphere (16, 16, wire); glPopMatrix(); #endif }
/* simple filled sphere */ static Bool mySphere(float radius) { #if 0 GLUquadricObj *quadObj; if((quadObj = gluNewQuadric()) == 0) return False; gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL); gluSphere(quadObj, radius, 16, 16); gluDeleteQuadric(quadObj); #else glPushMatrix(); glScalef (radius, radius, radius); glRotatef (90, 1, 0, 0); unit_sphere (16, 16, False); glPopMatrix(); #endif return True; }
ENTRYPOINT void init_planet (ModeInfo * mi) { planetstruct *gp; int screen = MI_SCREEN(mi); Bool wire = MI_IS_WIREFRAME(mi); if (planets == NULL) { if ((planets = (planetstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (planetstruct))) == NULL) return; } gp = &planets[screen]; if ((gp->glx_context = init_GL(mi)) != NULL) { reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } { //char *f = get_string_resource(mi->dpy, "imageForeground", "Foreground"); //char *b = get_string_resource(mi->dpy, "imageBackground", "Background"); char *f = _strdup(imageForeground); char *b = _strdup(imageBackground); char *s; if (!f) f = _strdup("white"); if (!b) b = _strdup("black"); for (s = f + strlen(f)-1; s > f; s--) if (*s == ' ' || *s == '\t') *s = 0; for (s = b + strlen(b)-1; s > b; s--) if (*s == ' ' || *s == '\t') *s = 0; if (!XParseColor(mi->dpy, mi->xgwa.colormap, f, &gp->fg)) { fprintf(stderr, "%s: unparsable color: \"%s\"\n", progname, f); exit(1); } if (!XParseColor(mi->dpy, mi->xgwa.colormap, b, &gp->bg)) { fprintf(stderr, "%s: unparsable color: \"%s\"\n", progname, f); exit(1); } free (f); free (b); } { double spin_speed = 0.5; double wander_speed = 0.02; gp->rot = make_rotator (do_roll ? spin_speed : 0, do_roll ? spin_speed : 0, 0, 1, do_wander ? wander_speed : 0, True); gp->z = frand (1.0); gp->trackball = gltrackball_init (); } if (wire) { do_texture = False; do_light = False; } if (do_texture) setup_texture (mi); if (do_light) init_sun (mi); if (do_stars) init_stars (mi); if (random() & 1) star_spin = -star_spin; /* construct the polygons of the planet */ gp->platelist = glGenLists(1); glNewList (gp->platelist, GL_COMPILE); glColor3f (1,1,1); glPushMatrix (); glScalef (RADIUS, RADIUS, RADIUS); glRotatef (90, 1, 0, 0); glFrontFace(GL_CCW); unit_sphere (resolution, resolution, wire); glPopMatrix (); glEndList(); /* construct the polygons of the latitude/longitude/axis lines. */ gp->latlonglist = glGenLists(1); glNewList (gp->latlonglist, GL_COMPILE); glPushMatrix (); glDisable (GL_TEXTURE_2D); glDisable (GL_LIGHTING); glDisable (GL_LINE_SMOOTH); glColor3f (0.1, 0.3, 0.1); glScalef (RADIUS, RADIUS, RADIUS); glScalef (1.01, 1.01, 1.01); glRotatef (90, 1, 0, 0); unit_sphere (12, 24, 1); glBegin(GL_LINES); glVertex3f(0, -2, 0); glVertex3f(0, 2, 0); glEnd(); glPopMatrix (); glEndList(); }
ENTRYPOINT void init_ball (ModeInfo *mi) { ball_configuration *bp; int wire = MI_IS_WIREFRAME(mi); MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_ball (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); if (!wire) { GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0}; GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } { double spin_speed = 10.0; double wander_speed = 0.12; double spin_accel = 2.0; bp->rot = make_rotator (do_spin ? spin_speed : 0, do_spin ? spin_speed : 0, do_spin ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, True); bp->trackball = gltrackball_init (True); } bp->ncolors = 128; bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor)); make_smooth_colormap (0, 0, 0, bp->colors, &bp->ncolors, False, 0, False); bp->spikes = (int *) calloc(MI_COUNT(mi), sizeof(*bp->spikes) * 2); bp->ball_list = glGenLists (1); bp->spike_list = glGenLists (1); glNewList (bp->ball_list, GL_COMPILE); unit_sphere (SPHERE_STACKS, SPHERE_SLICES, wire); glEndList (); glNewList (bp->spike_list, GL_COMPILE); cone (0, 0, 0, 0, 1, 0, 1, 0, SPIKE_FACES, SMOOTH_SPIKES, False, wire); glEndList (); randomize_spikes (mi); }
ENTRYPOINT void init_ball (ModeInfo *mi) { int wire = MI_IS_WIREFRAME(mi); blinkboxstruct *bp; if(blinkbox == NULL) { if((blinkbox = (blinkboxstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (blinkboxstruct))) == NULL) return; } bp = &blinkbox[MI_SCREEN(mi)]; if ((bp->glx_context = init_GL(mi)) != NULL) { reshape_ball(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); } else MI_CLEARWINDOW(mi); bp->ball.d = 1; bp->bscale.wh = bscale_wh; bp->bscale.d = 0.25; bp->mo.x = 1; bp->mo.y = 1; bp->mo.z = 1; bp->moh.x = -1.0; bp->moh.y = -1.5; bp->moh.z = -1.5; bp->bpos.x = 1; bp->bpos.y = 1; bp->bpos.z = 1; bp->des_amt = 1; bp->lside.counter = MAX_COUNT; bp->rside.counter = MAX_COUNT; bp->tside.counter = MAX_COUNT; bp->bside.counter = MAX_COUNT; bp->fside.counter = MAX_COUNT; bp->aside.counter = MAX_COUNT; bp->lside.color[0] = 1; bp->rside.color[1] = 1; bp->tside.color[2] = 1; bp->bside.color[0] = 1; bp->bside.color[1] = 0.5; bp->fside.color[0] = 1; bp->fside.color[1] = 1; bp->aside.color[0] = 0.5; bp->aside.color[2] = 1; bp->lside.rot[0] = 90; bp->rside.rot[0] = 90; bp->tside.rot[0] = 90; bp->bside.rot[0] = 90; bp->fside.rot[0] = 90; bp->aside.rot[0] = 90; bp->lside.rot[2] = 1; bp->rside.rot[2] = 1; bp->tside.rot[1] = 1; bp->bside.rot[1] = 1; bp->fside.rot[3] = 1; bp->aside.rot[3] = 1; bp->lside.des_count = 1; bp->rside.des_count = 1; bp->tside.des_count = 1; bp->bside.des_count = 1; bp->fside.des_count = 1; bp->aside.des_count = 1; bp->lside.alpha_count = 1; bp->rside.alpha_count = 1; bp->tside.alpha_count = 1; bp->bside.alpha_count = 1; bp->fside.alpha_count = 1; bp->aside.alpha_count = 1; #define SPHERE_SLICES 12 /* how densely to render spheres */ #define SPHERE_STACKS 16 bp->sp = malloc(sizeof(*bp->sp)); if(bp->sp == NULL){ fprintf(stderr,"Could not allocate memory\n"); exit(1); } if( (bp->bscale.wh < 1) || (bp->bscale.wh > 8) ) { fprintf(stderr,"Boxsize out of range. Using default\n"); bp->bscale.wh = 2; } if (do_dissolve){ bp->des_amt = bp->bscale.wh / MAX_COUNT; } reshape_ball(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); bp->ballList = glGenLists(1); glNewList(bp->ballList, GL_COMPILE); unit_sphere (SPHERE_STACKS, SPHERE_SLICES, wire); glEndList (); bp->boxList = glGenLists(1); glNewList(bp->boxList, GL_COMPILE); unit_cube(wire); glEndList(); if (wire) return; glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_LIGHTING); glClearDepth(1); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); glEnable(GL_LIGHT1); if (do_fade || do_blur) { glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); } }
ENTRYPOINT void init_planet (ModeInfo * mi) { planetstruct *gp; int screen = MI_SCREEN(mi); Bool wire = MI_IS_WIREFRAME(mi); MI_INIT (mi, planets); gp = &planets[screen]; gp->window = MI_WINDOW(mi); if ((gp->glx_context = init_GL(mi)) != NULL) { reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } { char *f = get_string_resource(mi->dpy, "imageForeground", "Foreground"); char *b = get_string_resource(mi->dpy, "imageBackground", "Background"); char *s; if (!f) f = strdup("white"); if (!b) b = strdup("black"); for (s = f + strlen(f)-1; s > f; s--) if (*s == ' ' || *s == '\t') *s = 0; for (s = b + strlen(b)-1; s > b; s--) if (*s == ' ' || *s == '\t') *s = 0; free (f); free (b); } { double spin_speed = 0.1; double wander_speed = 0.005; gp->rot = make_rotator (do_roll ? spin_speed : 0, do_roll ? spin_speed : 0, 0, 1, do_wander ? wander_speed : 0, True); gp->z = frand (1.0); gp->tilt = frand (23.4); gp->trackball = gltrackball_init (True); } if (!wire && !do_texture) { GLfloat pos[4] = {1, 1, 1, 0}; GLfloat amb[4] = {0, 0, 0, 1}; GLfloat dif[4] = {1, 1, 1, 1}; GLfloat spc[4] = {0, 1, 1, 1}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } if (wire) do_texture = False; if (do_texture) setup_texture (mi); if (do_stars) init_stars (mi); /* construct the polygons of the planet */ gp->platelist = glGenLists(1); glNewList (gp->platelist, GL_COMPILE); glFrontFace(GL_CCW); glPushMatrix(); glRotatef (90, 1, 0, 0); unit_sphere (resolution, resolution, wire); glPopMatrix(); glEndList(); gp->shadowlist = glGenLists(1); glNewList (gp->shadowlist, GL_COMPILE); glFrontFace(GL_CCW); if (wire) glColor4f (0.5, 0.5, 0, 1); # ifdef BLENDED_TERMINATOR else { GLfloat c[] = { 0, 0, 0, 1 }; glColor4fv (c); if (!do_texture) glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c); } # endif glPushMatrix(); glScalef (1.01, 1.01, 1.01); unit_dome (resolution, resolution, wire); # ifdef BLENDED_TERMINATOR terminator_tube (mi, resolution); if (!wire) { /* We have to draw the transparent side of the mask too, though I'm not sure why. */ GLfloat c[] = { 0, 0, 0, 0 }; glColor4fv (c); if (!do_texture) glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c); glRotatef (180, 1, 0, 0); unit_dome (resolution, resolution, wire); } # endif glPopMatrix(); glEndList(); /* construct the polygons of the latitude/longitude/axis lines. */ gp->latlonglist = glGenLists(1); glNewList (gp->latlonglist, GL_COMPILE); glPushMatrix (); glRotatef (90, 1, 0, 0); /* unit_sphere is off by 90 */ glRotatef (8, 0, 1, 0); /* line up the time zones */ unit_sphere (12, 24, 1); unit_sphere (12, 24, 1); glBegin(GL_LINES); glVertex3f(0, -2, 0); glVertex3f(0, 2, 0); glEnd(); glPopMatrix (); glEndList(); }