/* Demonstrates the difference between directional and positional lights. It uses a sphere, so that we're guaranteed to get specular highlights. Written by Scott D. Anderson scott.anderson@acm.org Fall 2004 */ #include #include #include void display(void) { twDisplayInit(); twCamera(); GLfloat light0Pos[] = {0, 0, 1, 0}; twGrayLight(GL_LIGHT0,light0Pos,1,1,1); GLfloat light1Pos[] = {0, 0, 1, 1}; twGrayLight(GL_LIGHT1,light1Pos,1,1,1); 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 glPopMatrix(); glEnable(GL_LIGHT1); glDisable(GL_LIGHT0); glPushMatrix(); glTranslatef(1,0,0); glutSolidSphere(1,30,30); // right ball 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); const float SIZE = 0.7; twBoundingBox(-2*SIZE,+2*SIZE,-SIZE,+SIZE,-SIZE,+SIZE); // a lie, to get us closer twMainInit(); glutMainLoop(); return 0; }