//================================================================================================================================== void PlatformerMap::ClipSprites() { // if(x >= -150 && x < screenWidth) vector<AISprite*> renderList(MAX_SPRITES); for (int j = 0; j < m_Sprites.size(); j++) { if (m_Sprites[j] == NULL) continue; AISprite* spr = m_Sprites[j]; if (InScreen(spr->X(), spr->Y())) { renderList[j] = spr; } } //Fix the render list based on the clipping of each sprite if (m_Sprites.size() > 0) { if (m_ClippedSprites.size() > 0) m_ClippedSprites.clear(); m_numSpritesRendered = 0; for (int j = 0; j < renderList.size(); j++) { if (renderList[j] != NULL) m_numSpritesRendered++; m_ClippedSprites.push_back( renderList[j] ); } } }
static int make_bit (ModeInfo *mi, bit_state which) { static const GLfloat spec[4] = {1.0, 1.0, 1.0, 1.0}; static const GLfloat shiny = 128.0; const GLfloat *color = colors[which]; int wire = MI_IS_WIREFRAME(mi); int polys = 0; GLfloat s; const struct gllist *gll; glMaterialfv (GL_FRONT, GL_SPECULAR, spec); glMateriali (GL_FRONT, GL_SHININESS, shiny); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); glColor4f (color[0], color[1], color[2], color[3]); glPushMatrix(); switch (which) { case BIT_IDLE1: glRotatef (-44, 0, 1, 0); /* line up the models with each other */ glRotatef (-11, 1, 0, 0); glRotatef ( 8, 0, 0, 1); s = 1.0; break; case BIT_IDLE2: glRotatef ( 16.0, 0, 0, 1); glRotatef (-28.0, 1, 0, 0); s = 1.0; break; case BIT_NO: glRotatef ( 16.0, 0, 0, 1); glRotatef (-28.0, 1, 0, 0); s = 1.6; break; case BIT_YES: glRotatef (-44.0, 0, 1, 0); glRotatef (-32.0, 1, 0, 0); s = 1.53; break; default: abort(); break; } glScalef (s, s, s); gll = *all_objs[which]; renderList (gll, wire); polys += gll->points / 3; glPopMatrix(); return polys; }
ENTRYPOINT void init_camera (ModeInfo *mi) { camera_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; MI_INIT (mi, bps, 0); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_camera (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.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); } bp->user_trackball = gltrackball_init (False); bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; char *key = 0; GLfloat spec1[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat spec2[4] = {0.40, 0.40, 0.70, 1.0}; GLfloat *spec = spec1; GLfloat shiny = 20; glNewList (bp->dlists[i], GL_COMPILE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef (-90, 1, 0, 0); glRotatef (180, 0, 0, 1); glScalef (6, 6, 6); glBindTexture (GL_TEXTURE_2D, 0); switch (i) { case CAMERA_BODY: key = "bodyColor"; break; case CAMERA_CAP: key = "capColor"; break; case CAMERA_HINGE: key = "hingeColor"; break; case CAMERA_MOUNT: key = "mountColor"; break; case CAMERA_LENS: key = "lensColor"; spec = spec2; break; case GROUND: key = "groundColor"; spec = spec2; shiny = 128; break; default: abort(); break; } parse_color (mi, key, bp->component_colors[i]); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); switch (i) { case GROUND: if (! ground) ground = (struct gllist *) calloc (1, sizeof(*ground)); ground->points = draw_ground (mi, bp->component_colors[i]); break; default: renderList (gll, wire); /* glColor3f (1, 1, 1); renderListNormals (gll, 100, True); */ /* glColor3f (1, 1, 0); renderListNormals (gll, 100, False); */ break; } glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEndList (); } bp->ncameras = MI_COUNT(mi); if (bp->ncameras <= 0) bp->ncameras = 1; bp->cameras = (camera *) calloc (bp->ncameras, sizeof (camera)); { GLfloat range = (MI_COUNT(mi) <= 2) ? 4 : 5.5; GLfloat extent; GLfloat spacing = range / bp->ncameras; if (spacing < 0.7) spacing = 0.7; extent = spacing * (bp->ncameras - 1); for (i = 0; i < bp->ncameras; i++) { camera *c = &bp->cameras[i]; c->state = IDLE; c->pos.x = i*spacing - extent/2; c->pos.z += 0.7; if (spacing < 1.6) c->pos.z = (i & 1 ? 1.1 : -0.3); c->focus.x = c->pos.x; c->focus.y = c->pos.y + 1; c->focus.z = c->pos.z + BEAM_ZOFF; c->pitch = -50; } } # ifdef DEBUG if (!debug_p) # endif /* Let's tilt the floor a little. */ gltrackball_reset (bp->user_trackball, -0.70 + frand(1.58), -0.30 + frand(0.40)); }
ENTRYPOINT void init_toasters (ModeInfo *mi) { toaster_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; if (!bps) { bps = (toaster_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (toaster_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_toasters (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.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); } if (!wire && do_texture) load_textures (mi); bp->user_trackball = gltrackball_init (); auto_track_init (mi); bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef (-90, 1, 0, 0); glRotatef (180, 0, 0, 1); glScalef (6, 6, 6); glBindTexture (GL_TEXTURE_2D, 0); if (i == BASE_TOASTER) { GLfloat color[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); if (do_texture) glBindTexture (GL_TEXTURE_2D, bp->chrome_texture); # ifndef HAVE_JWZGLES glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); # endif } else if (i == TOAST || i == TOAST_BITTEN) { GLfloat color[4] = {0.80, 0.80, 0.00, 1.0}; GLfloat spec[4] = {0.00, 0.00, 0.00, 1.0}; GLfloat shiny = 0.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); if (do_texture) glBindTexture (GL_TEXTURE_2D, bp->toast_texture); # ifndef HAVE_JWZGLES glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); # endif glMatrixMode(GL_TEXTURE); glTranslatef(0.5, 0.5, 0); glMatrixMode(GL_MODELVIEW); } else if (i == SLOTS || i == HANDLE_SLOT) { GLfloat color[4] = {0.30, 0.30, 0.40, 1.0}; GLfloat spec[4] = {0.40, 0.40, 0.70, 1.0}; GLfloat shiny = 128.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == HANDLE) { GLfloat color[4] = {0.80, 0.10, 0.10, 1.0}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == KNOB) { GLfloat color[4] = {0.80, 0.10, 0.10, 1.0}; GLfloat spec[4] = {0.00, 0.00, 0.00, 1.0}; GLfloat shiny = 0.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == JET || i == JET_WING) { GLfloat color[4] = {0.70, 0.70, 0.70, 1.0}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == BASE) { GLfloat color[4] = {0.50, 0.50, 0.50, 1.0}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else { GLfloat color[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 128.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } renderList (gll, wire); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEndList (); } bp->nfloaters = ntoasters + nslices; bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater)); for (i = 0; i < bp->nfloaters; i++) { floater *f = &bp->floaters[i]; /* arrange the list so that half the toasters are in front of bread, and half are behind. */ f->toaster_p = ((i < ntoasters / 2) || (i >= (nslices + (ntoasters / 2)))); reset_floater (mi, f); /* Position the first generation randomly, but make sure they aren't on screen yet (until we rotate the view into position.) */ { GLfloat min = -GRID_DEPTH/2; GLfloat max = GRID_DEPTH/3.5; f->z = frand (max - min) + min; } } }
ENTRYPOINT void init_splitflap (ModeInfo *mi) { splitflap_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_splitflap (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); bp->first_time_p = True; if (!mode_str || !*mode_str || !strcasecmp(mode_str, "text")) { bp->clock_p = 0; } else if (!strcasecmp (mode_str, "clock") || !strcasecmp (mode_str, "clock12")) { bp->clock_p = 12; grid_width = 8; grid_height = 1; } else if (!strcasecmp (mode_str, "clock24")) { bp->clock_p = 24; grid_width = 6; grid_height = 1; } else { fprintf (stderr, "%s: `mode' must be text, clock12 or clock24: not `%s'\n", progname, mode_str); exit (1); } if (! bp->clock_p) { bp->tc = textclient_open (MI_DISPLAY (mi)); bp->text[0] = 0; if (grid_width > 10) textclient_reshape (bp->tc, grid_width, grid_height, grid_width, grid_height, 0); } if (bp->clock_p) speed /= 4; glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.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); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } { double spin_speed = 0.5; double wander_speed = 0.005; double tilt_speed = 0.001; double spin_accel = 0.5; char *s = do_spin; while (*s) { if (*s == 'x' || *s == 'X') bp->spinx = True; else if (*s == 'y' || *s == 'Y') bp->spiny = True; else if (*s == 'z' || *s == 'Z') bp->spinz = True; else if (*s == '0') ; else { fprintf (stderr, "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n", progname, do_spin); exit (1); } s++; } bp->rot = make_rotator (bp->spinx ? spin_speed : 0, bp->spiny ? spin_speed : 0, bp->spinz ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, False); bp->rot2 = (face_front_p ? make_rotator (0, 0, 0, 0, tilt_speed, True) : 0); bp->trackball = gltrackball_init (False); } bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); parse_color (mi, "textColor", bp->text_color); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; char *key = 0; GLfloat spec[4] = {0.4, 0.4, 0.4, 1.0}; GLfloat shiny = 80; /* 0-128 */ glNewList (bp->dlists[i], GL_COMPILE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef (-90, 1, 0, 0); glBindTexture (GL_TEXTURE_2D, 0); switch (i) { case SPLITFLAP_QUARTER_FRAME: key = "frameColor"; break; case SPLITFLAP_OUTER_FRAME: key = "caseColor"; break; case SPLITFLAP_DISC_QUARTER: key = (wire ? "frameColor" : "discColor"); break; case SPLITFLAP_FIN_EDGE_HALF: case SPLITFLAP_FIN_FACE_HALF: key = "finColor"; break; default: abort(); } parse_color (mi, key, bp->component_colors[i]); if (wire && i == SPLITFLAP_FIN_EDGE_HALF) bp->component_colors[i][0] = bp->component_colors[i][1] = bp->component_colors[i][2] = 0.7; glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); switch (i) { case SPLITFLAP_OUTER_FRAME: if (! splitflap_obj_outer_frame) splitflap_obj_outer_frame = (struct gllist *) calloc (1, sizeof(*splitflap_obj_outer_frame)); splitflap_obj_outer_frame->points = draw_outer_frame(mi); break; default: renderList (gll, wire); break; } glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEndList (); } if (grid_width < 1) grid_width = 1; if (grid_height < 1) grid_height = 1; bp->flappers = (flapper *) calloc (grid_width * grid_height, sizeof (flapper)); for (i = 0; i < grid_width * grid_height; i++) { flapper *f = &bp->flappers[i]; if (!bp->clock_p) { f->spool = ascii_spool; f->spool_size = countof (ascii_spool); } else { switch (i) { case 0: if (bp->clock_p == 12) { f->spool = digit_s1_spool; f->spool_size = countof (digit_s1_spool); } else { f->spool = digit_01_spool; f->spool_size = countof (digit_01_spool); } break; case 1: case 3: case 5: f->spool = digit_spool; f->spool_size = countof (digit_spool); break; case 2: case 4: f->spool = digit_05_spool; f->spool_size = countof (digit_05_spool); break; case 6: f->spool = ap_spool; f->spool_size = countof (ap_spool); break; case 7: f->spool = m_spool; f->spool_size = countof (m_spool); break; default: abort(); } } f->target_index = random() % f->spool_size; /* f->target_index = 0; */ f->current_index = f->target_index; f->missing = (((random() % 10) == 0) ? (random() % f->spool_size) : -1); } bp->font_data = load_texture_font (mi->dpy, "flapFont"); init_textures (mi); reshape_splitflap (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); }
int main(int argc, char* argv[]) { sSdlWrapper* wrap = initializeSDLWrapper("Snake", 800, 600, 32, 1, 1); game* gameEngine = initGame(wrap, 32, 24); int Selection = 0; sTextGFX* startUnsel = createText(wrap, "Start Game", 0xFFFFFFFF); sTextGFX* startSel = createText(wrap, "Start Game", 0xFFFFF000); sTextGFX* exitUnsel = createText(wrap, "Exit Game" , 0xFFFFFFFF); sTextGFX* exitSel = createText(wrap, "Exit Game" , 0xFFFFF000); sLinkedList* titleList = 0; FILE* titleFile = fopen("snake.pic", "r"); listInitialize(&titleList, sizeofPoint(), NULL); for(int x = 0; x < 32; x++) for(int y = 0; y < 24; y++) if(x == 0 || x == (31) || y == 0 || y == (23)) { point* toAdd = createPoint(x,y); listPushFront(titleList, (void*)toAdd); free(toAdd); } while(isRunning(wrap)) { beginFrame(wrap); if(State == -1) { readTitleFile(titleList, titleFile); renderList(titleList, wrap); } else if(State == 1) tick(gameEngine); else { if(Selection == 0) { renderText(wrap, startSel, 400, 300); renderText(wrap, exitUnsel, 400, 325); } else { renderText(wrap, startUnsel, 400, 300); renderText(wrap, exitSel, 400, 325); } if(keyDown(wrap, SDLK_DOWN)) Selection = 1; if(keyDown(wrap,SDLK_UP)) Selection = 0; if(keyDown(wrap, SDLK_RETURN)) { if(Selection == 0) { State = 1; setupGame(gameEngine); } else toggleRunning(wrap); } renderList(titleList, wrap); } if(keyPressed(wrap, SDLK_ESCAPE)) toggleRunning(wrap); endFrame(wrap); } listClear(titleList); free(titleList); destroyText(startUnsel); destroyText(startSel); destroyText(exitUnsel); destroyText(exitSel); deinitializeWrapper(wrap); destroyGame(gameEngine); free(wrap); return 0; }
ENTRYPOINT void init_cube (ModeInfo *mi) { cube_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; if (!bps) { bps = (cube_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (cube_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_cube (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.7, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.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); } bp->trackball = gltrackball_init (); bp->dlists = (GLuint *) calloc (countof(all_objs)+2, sizeof(GLuint)); for (i = 0; i < countof(all_objs)+1; i++) bp->dlists[i] = glGenLists (1); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); renderList (gll, wire); glEndList (); } glNewList (bp->dlists[i], GL_COMPILE); bp->cube_polys = build_cube (mi); glEndList (); bp->nfloaters = MI_COUNT (mi); bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater)); for (i = 0; i < bp->nfloaters; i++) { floater *f = &bp->floaters[i]; double spin_speed = do_spin ? 0.7 : 10; double wander_speed = do_wander ? 0.02 : 0.05 * speed * SPEED_SCALE; double spin_accel = 0.5; f->rot = make_rotator (spin_speed, spin_speed, spin_speed, spin_accel, wander_speed, True); if (bp->nfloaters == 2) { f->x = (i ? 2 : -2); } else if (i != 0) { double th = (i - 1) * M_PI*2 / (bp->nfloaters-1); double r = 3; f->x = r * cos(th); f->z = r * sin(th); } f->ix = f->x; f->iy = f->y; f->iz = f->z; reset_floater (mi, f); } }
ENTRYPOINT void init_cow (ModeInfo *mi) { cow_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; Bool tex_p = False; MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_cow (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.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); } bp->trackball = gltrackball_init (False); bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); tex_p = load_texture (mi, do_texture); if (tex_p) glBindTexture (GL_TEXTURE_2D, bp->texture); for (i = 0; i < countof(all_objs); i++) { GLfloat black[4] = {0, 0, 0, 1}; const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); glDisable (GL_TEXTURE_2D); if (i == HIDE) { GLfloat color[4] = {0.63, 0.43, 0.36, 1.00}; if (tex_p) { /* if we have a texture, make the base color be white. */ color[0] = color[1] = color[2] = 1.0; glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); /* approximately line it up with ../images/earth.png */ glMatrixMode (GL_TEXTURE); glLoadIdentity(); glTranslatef (0.45, 0.58, 0); glScalef (0.08, 0.16, 1); glRotatef (-5, 0, 0, 1); glMatrixMode (GL_MODELVIEW); } glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128); } else if (i == TAIL) { GLfloat color[4] = {0.63, 0.43, 0.36, 1.00}; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128); } else if (i == UDDER) { GLfloat color[4] = {1.00, 0.53, 0.53, 1.00}; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128); } else if (i == HOOFS || i == HORNS) { GLfloat color[4] = {0.20, 0.20, 0.20, 1.00}; GLfloat spec[4] = {0.30, 0.30, 0.30, 1.00}; GLfloat shiny = 8.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == FACE) { GLfloat color[4] = {0.10, 0.10, 0.10, 1.00}; GLfloat spec[4] = {0.10, 0.10, 0.10, 1.00}; GLfloat shiny = 8.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else { GLfloat color[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat shiny = 128.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } renderList (gll, wire); glEndList (); } bp->nfloaters = MI_COUNT (mi); bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater)); for (i = 0; i < bp->nfloaters; i++) { floater *f = &bp->floaters[i]; f->rot = make_rotator (10.0, 0, 0, 4, 0.05 * speed, True); if (bp->nfloaters == 2) { f->x = (i ? 6 : -6); } else if (i != 0) { double th = (i - 1) * M_PI*2 / (bp->nfloaters-1); double r = 10; f->x = r * cos(th); f->z = r * sin(th); } f->ix = f->x; f->iy = f->y; f->iz = f->z; reset_floater (mi, f); } }