void display (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); drawAxis(); glEnable(GL_LIGHTING); glColor3f (1., 0, 0.); renderScene(); float ground[4] = {1,0,0,4}; myShadowMatrix(ground, position); glColor3f (0.5, 0.5, 0.5); renderScene(); glFlush (); }
void myInit(void) { /* glGetIntegerv(GL_MAX_CLIP_PLANES, nest); printf("GL_MAX_CLIP_PLANES are %d \n", nest[0]); */ /*%%%%%%%% Initialize Positional Light and Ambient Light %%%%%%%%*/ #if 0 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); #endif #if 0 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff); glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpec); glEnable(GL_LIGHT0); #endif /*** Initial light position is declared in the display function ***/ glLightfv(GL_LIGHT1, GL_AMBIENT, light1Amb); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1Diff); glLightfv(GL_LIGHT1, GL_SPECULAR, light1Spec); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); /* glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.7);*/ /* glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.04);*/ /* use 0.04 w/ 24 bit color */ glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.07); /* try 0.07 w/ 24 bit color */ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ /*########### Initialize Fog ##################*/ /* { GLfloat fog_color[] = {0.5, 0.5, 0.5, 1.0}; GLfloat fog_start[] = {0.0, 0.0, 1.0, 20.0}; glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fog_color); glFogf(GL_FOG_DENSITY, 0.35); glFogfv(GL_FOG_START, fog_start); glHint(GL_FOG_HINT, GL_FASTEST); } */ /*##########################################*/ /*....Shadow Matrices For Floor, Left Wall, Back Wall, and Right Wall......*/ /* For light0 */ myShadowMatrix(groundPlane, lightPos, shadowMat_ground); myShadowMatrix(leftPlane, lightPos, shadowMat_left); myShadowMatrix(columnPlane, lightPos, shadowMat_column); myShadowMatrix(backPlane, lightPos, shadowMat_back); myShadowMatrix(rightPlane, lightPos, shadowMat_right); /* For light1 */ myShadowMatrix(groundPlane, light1Pos, shadowMat1_ground); myShadowMatrix(leftPlane, light1Pos, shadowMat1_left); myShadowMatrix(backPlane, light1Pos, shadowMat1_back); myShadowMatrix(rightPlane, light1Pos, shadowMat1_right); /*.......................................................................*/ /*sssssssssssssssss Make Satellite Body and Shadow ssssssssssssssssssssssss*/ glNewList(satellite1, GL_COMPILE); glPushMatrix(); drawSatellite(satellite_diffuse, satellite_ambient, satellite_specular, satellite_shiny); glPopMatrix(); glEndList(); glNewList(satellite2, GL_COMPILE); glPushMatrix(); drawSatellite(shadow_diffuse, shadow_ambient, shadow_specular, shadow_shiny); glPopMatrix(); glEndList(); /*sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss*/ /*ppppppppppppppppppppppppppp Make Solar Panels and Shadows pppppppppppppppppp*/ glNewList(panel1, GL_COMPILE); glPushMatrix(); drawPanels(panel_color, panel_ambient); glPopMatrix(); glEndList(); glNewList(panel2, GL_COMPILE); glPushMatrix(); drawPanels(shadow_diffuse, shadow_ambient); glPopMatrix(); glEndList(); /*pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp*/ /*========= Make Floor ==============*/ glNewList(ground, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_DIFFUSE, floor_color); glMaterialfv(GL_FRONT, GL_AMBIENT, shadow_ambient); glTranslatef(0.0, -1.5, -5.0); glRotatef(-90.0, 1, 0, 0); glScalef(5.0, 5.0, 1.0); drawGround(); /* draw ground */ glPopAttrib(); glPopMatrix(); glEndList(); /*==================================*/ /*@@@@@@@@@@ Make Lamp Post and Lamp @@@@@@@@@@@@*/ glNewList(21, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_AMBIENT, lamp_post_specular); glTranslatef(0.0, -0.1, -5.0); glScalef(0.07, 1.45, 0.07); drawCube(lamp_post_diffuse, lamp_post_ambient); /* draw lamp post */ glPopAttrib(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, -1.45, -5.0); glScalef(0.3, 0.05, 0.3); drawCube(wall_color, cube_ambient); /* draw lamp post base */ glPopMatrix(); glEndList(); glNewList(22, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_AMBIENT, lamp_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, lamp_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, lamp_specular); glTranslatef(0.0, 1.6, -5.0); glutSolidSphere(0.3, 20.0, 20.0); /* draw lamp */ glPopAttrib(); glPopMatrix(); glEndList(); /*** Lamp post base shadow ***/ glNewList(501, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_AMBIENT, shadow_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, shadow_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, shadow_specular); glMaterialfv(GL_FRONT, GL_SHININESS, shadow_shiny); glTranslatef(0.0, -1.49, -5.0); glRotatef(-90.0, 1.0, 0.0, 0.0); glScalef(0.7, 0.7, 1.0); drawOct(); glPopAttrib(); glPopMatrix(); glEndList(); /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ /*||||||||||| Make Left Wall |||||||||||||*/ glNewList(left_wall, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_DIFFUSE, wall_color); glMaterialfv(GL_FRONT, GL_AMBIENT, wall_ambient); glTranslatef(0.0, -1.5, 0.0); glTranslatef(0.0, 1.2, 0.0); glTranslatef(0.0, 0.0, -5.0); glTranslatef(-5.0, 0.0, 0.0); glRotatef(90.0, 0, 1, 0); glScalef(4.5, 1.2, 1.0); glNormal3f (0.0, 0.0, 1.0); drawGround(); /* draw left wall */ glPopAttrib(); glPopMatrix(); glEndList(); /*||||||||||||||||||||||||||||||||||||||||*/ /*\\\\\\\\\\\\\ Make Right Wall \\\\\\\\\\\\\\\\\\\*/ glNewList(right_wall, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_DIFFUSE, wall_color); glMaterialfv(GL_FRONT, GL_AMBIENT, wall_ambient); glTranslatef(0.0, -1.5, 0.0); glTranslatef(0.0, 1.2, 0.0); glTranslatef(0.0, 0.0, -5.0); glTranslatef(5.0, 0.0, 0.0); glRotatef(270.0, 0, 1, 0); glScalef(4.5, 1.2, 1.0); glNormal3f (0.0, 0.0, 1.0); drawGround(); /* draw right wall */ glPopAttrib(); glPopMatrix(); glEndList(); /*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ /*[[[[[[[[[[[ Build Columns ]]]]]]]]]]]*/ glPushMatrix(); glNewList(1, GL_COMPILE); glPushMatrix(); glScalef(0.4, 1.4, 0.4); drawCube(column_color, column_ambient); /* draw column1 */ glPopMatrix(); glEndList(); glNewList(2, GL_COMPILE); glPushMatrix(); glTranslatef(0.0, -1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(wall_color, cube_ambient); /* draw base */ glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(wall_color, cube_ambient); /* draw top */ glPopMatrix(); glEndList(); glPopMatrix(); glNewList(column, GL_COMPILE); glPushMatrix(); glCallList(1); glCallList(2); glPopMatrix(); glEndList(); /***** Place columns at front of scene. *****/ glNewList(4, GL_COMPILE); glPushMatrix(); glTranslatef(-5.0, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); glNewList(5, GL_COMPILE); glPushMatrix(); glTranslatef(-1.75, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); glNewList(6, GL_COMPILE); glPushMatrix(); glTranslatef(1.75, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); glNewList(17, GL_COMPILE); glPushMatrix(); glTranslatef(5.0, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); /*** Get the modelview matrix once ***/ glPushMatrix(); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) four_columnsXform); glPopMatrix(); glNewList(four_columns, GL_COMPILE); glPushMatrix(); glCallList(4); glCallList(5); glCallList(6); glCallList(17); glPopMatrix(); glEndList(); /***** Make two columns for sides of scene *****/ glNewList(two_columns, GL_COMPILE); glPushMatrix(); glRotatef(90.0, 0.0, 1.0, 0.0); glTranslatef(5.0, 0.0, -5.0); glPushMatrix(); glTranslatef(0.0, 0.0, -0.3); glCallList(column); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 0.0, 10.3); glCallList(column); glPopMatrix(); glPopMatrix(); glEndList(); /*[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]*/ /* .......................Make shadows .........................*/ glPushMatrix(); glNewList(8, GL_COMPILE); glPushMatrix(); glScalef(0.4, 1.4, 0.4); drawCube(shadow_diffuse, shadow_ambient); /* draw column1 */ glPopMatrix(); glEndList(); glNewList(9, GL_COMPILE); glPushMatrix(); glTranslatef(0.0, -1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(shadow_diffuse, shadow_ambient); /* draw base. */ glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(shadow_diffuse, shadow_ambient); /* draw top. */ glPopMatrix(); glEndList(); glPopMatrix(); glNewList(10, GL_COMPILE); glPushMatrix(); glCallList(8); glCallList(9); glPopMatrix(); glEndList(); glNewList(11, GL_COMPILE); glPushMatrix(); glTranslatef(-5.0, 0.0, -0.5); glCallList(10); glPopMatrix(); glEndList(); glNewList(12, GL_COMPILE); glPushMatrix(); glTranslatef(-1.75, 0.0, -0.5); glCallList(10); glPopMatrix(); glEndList(); glNewList(13, GL_COMPILE); glPushMatrix(); glTranslatef(1.75, 0.0, -0.5 ); glCallList(10); glPopMatrix(); glEndList(); glNewList(14, GL_COMPILE); glPushMatrix(); glTranslatef(5.0, 0.0, -0.5 ); glCallList(10); glPopMatrix(); glEndList(); glNewList(15, GL_COMPILE); glPushMatrix(); glCallList(11); glCallList(12); glCallList(13); glCallList(14); glPopMatrix(); glEndList(); glNewList(100, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_ground); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); glNewList(101, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_left); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); glNewList(102, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_back); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); glNewList(103, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_right); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); /* ......................................................*/ }