/* filename: mmoore2-Maui.cc written by: maui moore date: 15 November 2007 description: Palm Tree Demo with sun and global ambient lighting */ #include #include #include //#include "mmoore2a.cpp" #include GLfloat global_ambient[] = {0.5,0.5,0.5,1}; //high ambient because tropical! GLfloat sun[] = {1.0,1.0,1.0,0.0}; GLfloat sun_pos[] = {15, 15,15}; GLfloat sun_spec[] = {9.0, 9.0,9.0, 0.0}; GLfloat sun_dir[] = {0, -1, 0}; twTriple palmColor1 = {0, 1.0, 0}; twTriple palmColor2 = {0, .80, .1}; twTriple palmColor3 = {.25, .75, .5}; twTriple coconutColor = {.8, .25,.35}; twTriple trunkColor = {1.0, 0.9, 0.0}; twTriple ocean_color = {.25, 1.0, .90}; twTriple sun_color = {1.0, .69, 0}; const int treeHeight = 10; const int treeBase = 1; void sun_light() { /* for some reason sun makes one set of palms look blue */ twColor(sun_color,1.0, 100); glTranslatef(15,15,15); /* draw sphere to represent sun */ glutSolidSphere(2,50,50 ); glLightfv(GL_LIGHT0, GL_POSITION, sun_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, sun); glLightfv(GL_LIGHT0, GL_DIFFUSE, sun); glLightfv(GL_LIGHT0, GL_SPECULAR, sun_spec); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, sun_dir); glEnable(GL_LIGHT0); } void ambient_light() { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); glEnable(GL_LIGHTING); } void display (void) { twDisplayInit(); twCamera(); twColor(ocean_color,.9, 120); glBegin(GL_POLYGON); //draw bottom of bounding box or floor { glNormal3f(0,1,0); glVertex3f(0,0,0); glVertex3f(15,0,0); glVertex3f(15,0,15); glVertex3f(0,0,15); } glEnd(); mmoore2LitPalmTree(palmColor1, palmColor2,palmColor3, coconutColor, trunkColor,treeBase, treeHeight); ambient_light(); sun_light(); glFlush(); glutSwapBuffers(); } int main (int argc, char** argv) { /*code borrowed from Scott Anderson's Blocks.cc */ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(0,15,0,15,0,15); twMainInit(); glutMainLoop(); return 0; }