/* The teddy bear again, but now with two lights, that 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(); twAmbient(0.1); // turn down ambient to make the lights more obvious GLfloat light0[] = { 0.35, 0.4, 0.25, 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); twTeddyBear(); 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(-.35,.35,-.55,.4,-.25,.25); twMainInit(); twKeyCallback('1', lightToggle, "Toggle first light"); twKeyCallback('2', lightToggle, "Toggle second light"); glutDisplayFunc(display); glutMainLoop(); return 0; }