/* The teapot, but with two lights, which can be turned on/off independently. Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 Fall 2005, added a second light and the key callbacks. */ #include #include bool Light0 = true; bool Light1 = true; void display(void) { twDisplayInit(); twCamera(); glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); twAmbient(0); // turn down ambient to make the lights more obvious GLfloat light0[] = { 1, 1, 1, 1 }; twGrayLight(GL_LIGHT0, light0, 0.1, 0.7, 0.7); if(Light0) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); GLfloat light1[] = { 0, 1, 0, 0 }; twGrayLight(GL_LIGHT1, light1, 0.1, 0.8, 0.8); if(Light1) glEnable(GL_LIGHT1); else glDisable(GL_LIGHT1); twTriple pewter = {0.8, 0.8, 0.8}; twColor(pewter,0.9,64); glutSolidTeapot(1); glFlush(); glutSwapBuffers(); // necessary for animation } void lightToggle(unsigned char k, int x, int y) { switch(k) { case '1': Light0 = !Light0; break; case '2': Light1 = !Light1; break; } glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(650,650); glutCreateWindow(argv[0]); twBoundingBox(-1,+1,-1,+1,-1,+1); twMainInit(); twKeyCallback('1', lightToggle, "Toggle first light"); twKeyCallback('2', lightToggle, "Toggle second light"); glutDisplayFunc(display); glutMainLoop(); return 0; }