/* Demonstrates the difference between diffuse and specular lighting. The left ball only gets specular light, the right ball only gets diffuse light. Neither has any ambient light. Written by Scott D. Anderson scott.anderson@acm.org Fall 2004 */ #include #include #include void display(void) { twDisplayInit(); twCamera(); GLfloat light0Pos[] = {0, 0, 1, 1}; twGrayLight(GL_LIGHT0,light0Pos,1,0,1); GLfloat light1Pos[] = {0, 0, 1, 1}; twGrayLight(GL_LIGHT1,light1Pos,1,1,0); glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); twAmbient(0.2); twTriple objColor = {0.2, 0.3, 0.4}; twColor(objColor,0.9,20); glEnable(GL_LIGHT0); glDisable(GL_LIGHT1); glPushMatrix(); glTranslatef(-1,0,0); glutSolidSphere(1,30,30); // left ball gets specular light (light0) glPopMatrix(); glEnable(GL_LIGHT1); glDisable(GL_LIGHT0); glPushMatrix(); glTranslatef(1,0,0); glutSolidSphere(1,30,30); // right ball gets diffuse light (light1) glPopMatrix(); glFlush(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,300); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(-1,1,-0.7,0.7,-0.7,0.7); // a lie, to get us closer in twMainInit(); glutMainLoop(); return 0; }