/* Initialises texturing, lighting, display lists, and everything else associated with the model. */ void myinit(void) { GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat_shininess[] = {50.0}; GLfloat light_position1[] = {1.0, 1.0, 1.0, 0.0}; GLfloat light_position2[] = {-1.0, 1.0, 1.0, 0.0}; glClearColor(0.0, 0.0, 0.0, 0.0); obj = gluNewQuadric(); make_table(); make_image(); /* Set up Texturing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, 3, IMAGE_WIDTH, IMAGE_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, image); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); /* Set up Lighting */ glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position1); glLightfv(GL_LIGHT1, GL_POSITION, light_position2); /* Initial render mode is with full shading and LIGHT 0 enabled. */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); /* Initialise display lists */ glNewList(list_piston_shaded, GL_COMPILE); draw_piston(); glEndList(); glNewList(list_flywheel_shaded, GL_COMPILE); draw_flywheel(); glEndList(); gluQuadricTexture(obj, GL_TRUE); glNewList(list_piston_texture, GL_COMPILE); draw_piston(); glEndList(); glNewList(list_flywheel_texture, GL_COMPILE); draw_flywheel(); glEndList(); gluQuadricTexture(obj, GL_FALSE); }
/* Draws the complete crank. Piston also gets drawn through the crank bell function. */ void draw_crank(void) { glPushMatrix(); glRotatef(crank_angle, 1.0, 0.0, 0.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -1.0); myCylinder(obj, 0.08, 0.0, 1.4); glPopMatrix(); glPushMatrix(); glTranslatef(0.28, 0.0, 0.0); draw_crankbell(); glPopMatrix(); glPushMatrix(); glTranslatef(-0.77, 0.0, 0.0); if (shaded) { if (texture) glCallList(list_flywheel_texture); else glCallList(list_flywheel_shaded); } else draw_flywheel(); glPopMatrix(); glPopMatrix(); }