/* Demonstrates the use of shadows */ #include #include #include #include /* set up yellow light from origin */ void lighting() { GLfloat lightPosition [] = {0,0,0,1.0}; //point light source at origin GLfloat ambient [] = {1,1,0,1}; GLfloat diffuse [] = {1,1,0,1}; GLfloat specular [] = {1,1,1,1}; glShadeModel(GL_FLAT); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glEnable(GL_LIGHTING); } void display (void) { //code borrowed from Angel pg. 263 int i; GLfloat yl=5; GLfloat m[16]; //shadow projection matrix for (i=0;i<15;i++) m[i]=0.0; m[0]=m[5]=1.0; m[10]=1; m[7]=-1.0/yl; glClearColor(1,1,1,1); // clear screen to white glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); twCamera(); // sets up camera based on bounding box coords. twTriple lightGray = {0.7, 0.7, 0.7}; twColor(lightGray,0,0); glBegin(GL_POLYGON); glVertex3f(-10,10,5); glVertex3f(10,10,6); glVertex3f(0,10,-3); glEnd(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(-12,20,-2); twColorName(TW_YELLOW); glutSolidSphere(1,10,10); glMultMatrixf(m); glTranslatef(12,-20,2); twColorName(TW_RED); //original object glBegin(GL_POLYGON); glVertex3f(-10,10,5); glVertex3f(10,10,6); glVertex3f(0,10,-3); glEnd(); glPopMatrix(); glTranslatef(-10,0,0); twTriple gray = {0.6, 0.6, 0.6}; twColor(gray,0,0); // shadow color glutSolidTorus(2,5,20,20); glMatrixMode(GL_MODELVIEW); glPushMatrix(); // glTranslatef(-12,20,-2); glTranslatef(12,-20,2); twColorName(TW_BLUE); glutSolidSphere(1,10,10); glMultMatrixf(m); //glTranslatef(12,-20,2); glTranslatef(-12,20,-2); twColorName(TW_GREEN); glutSolidTorus(2,5,20,20); glPopMatrix(); glFlush(); glutSwapBuffers(); // necessary for animation } /*void display(void) { //this code is borrowed from Angel pg. 263 int i; GLfloat a=0; GLfloat b=-7; GLfloat c=0; GLfloat d=-2; GLfloat m[16]; // shadow projection matrix for (i=0;i<15;i++) m[i]=0.0; m[0]=m[5]=m[10]=-d; m[3]=a; m[7]=b; m[11]=c; glClearColor(1,1,1,1); // clear screen to white glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); twCamera(); // sets up camera based on bounding box coords. glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); twColor(0.7,0.7,0.7,70); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(a,b,c); glMultMatrixf(m); glTranslatef(-a,-b,-c); glDisable(GL_LIGHTING); twColor(0.7,0.7,0.7,10); glutSolidTeapot(10); glPopAttrib(); glPopMatrix(); glEnable(GL_LIGHTING); glFlush(); glutSwapBuffers(); // necessary for animation } */ int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); twBoundingBox(-20,20,-20,20,-20,20); // calculate near and far glutDisplayFunc(display); twMainInit(); //lighting(); glutMainLoop(); return 0; }