// This function draws a mailbox. The mailbox's origin is at the center at the base // of the post of the mailbox. // The mailbox is drawn upright, sitting on the x-z plane. // The opening of the mailbox is along the z axis and faces down the +ve z axis. // The user specifies the height of the mailbox as a float and // an integer choosing from one of 3 colors (0:red, 1:green, 2:purple) // The default mailbox is purple. // The mailbox's width is a third of the height specified and the depth // is about 2/3rds the height of the mailbox. // The length of the post of the mailbox is .6 of the height. // The post of the mailbox is automatically set to brown. void sdelrosaMailbox(float height, int color){ // load all the textures GLuint textureIDs[6]; glGenTextures(6, textureIDs); twLoadTexture(textureIDs[0], twPathname("mailboxRed.ppm",false)); twLoadTexture(textureIDs[1], twPathname("mailboxGreen.ppm",false)); twLoadTexture(textureIDs[2], twPathname("mailboxPurple.ppm",false)); // The length of the post from the ground float postHeight= height*.6; // The height of the curve of the mailbox from the base float curveHeight= height-postHeight; // The width of the base float baseWidth= height/3.0; // The depth of the base float baseDepth= height*2.0/3.0; // Brown for the post of the mailbox twTriple brown= {132.0/255.0, 64.0/255.0, 40.0/255.0}; glPushMatrix(); glTranslatef(0,postHeight*.5, 0); glScalef(.25, 1, .25); // The thickness of the post is .25 of the length twColor(brown, .4, 5); // Set the color glutSolidCube(postHeight); // Draw the post glPopMatrix(); glPushMatrix(); //Translate to top of post, back, left corner to draw base. glTranslatef(-baseWidth*.5,postHeight,-baseDepth*.5); // Control points for the curved surface (some vertices are used to draw base) GLfloat curve[16][3] = { {baseWidth,0,0}, // Points on the plane z=0 {baseWidth,curveHeight,0}, {0,curveHeight,0}, {0,0,0}, {baseWidth,0,baseDepth*.3}, // Points on the plane z=baseDepth*.3 {baseWidth,curveHeight,baseDepth*.3}, {0,curveHeight,baseDepth*.3}, {0,0,baseDepth*.3}, {baseWidth,0,baseDepth*.6}, // Points on the plane z=baseDepth*.6 {baseWidth,curveHeight,baseDepth*.6}, {0,curveHeight,baseDepth*.6}, {0,0,baseDepth*.6}, {baseWidth,0,baseDepth}, // Points on the plane z=baseDepth {baseWidth,curveHeight,baseDepth}, {0,curveHeight,baseDepth}, {0,0,baseDepth}, }; glEnable(GL_CULL_FACE); // Because we are drawing 2 sides // with opposite normals glBegin(GL_QUADS); // Draw the base { glNormal3f(0,1,0); glVertex3fv(curve[0]); glVertex3fv(curve[12]); glVertex3fv(curve[15]); glVertex3fv(curve[3]); glNormal3f(0,-1,0); glVertex3fv(curve[3]); glVertex3fv(curve[15]); glVertex3fv(curve[12]); glVertex3fv(curve[0]); } glEnd(); glDisable(GL_CULL_FACE); // Texture coordinates GLfloat texture[8] = { 1,1, 1,0, 0,1, 0,0 }; // Set the underlying color of the surface to white twTriple white= {1.0,1.0,1.0}; twColor(white,.7, 100); glEnable(GL_TEXTURE_2D); // Choosing which color to use for the mailbox if(color==0){ glBindTexture(GL_TEXTURE_2D, textureIDs[0]); }else if (color==1){ glBindTexture(GL_TEXTURE_2D, textureIDs[1]); }else{ glBindTexture(GL_TEXTURE_2D, textureIDs[2]); } // Draw the curved surface glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, curve[0]); glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2,texture); glEnable(GL_MAP2_VERTEX_3); glEnable(GL_MAP2_TEXTURE_COORD_2); glEnable(GL_AUTO_NORMAL); glMapGrid2f(10,0,1,10,0,1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_NORMALIZE); glEvalMesh2(GL_FILL, 0, 10, 0, 10); glDisable(GL_TEXTURE_2D); glPopMatrix(); }