p
key.w
key.r
key.initialisGL()
.
glShadeModel(GL_FLAT); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
void setUpGLUT(int argc,char ** argv)
with the following code.
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glClear(GL_COLOR_BUFFER_BIT);
in void display()
with the following code.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
initialiseGL()
.
glEnable(GL_DEPTH_TEST);
s
key.static int lighting=TRUE; static int light0=TRUE; case '0': light0=!light0; if(light0)glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0);break; case 'l': lighting=!lighting; if(lighting)glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING);break;
/* manage lighting */ enum {whiteLight,redLight,redLaserLight}; GLfloat ambient[][4]={ {0.5,0.5,0.5,1.0},{1.0,0.0,0.0,1.0},{0.05,0.0,0.0,1.0} }; GLfloat diffuse[][4]={ {1.0,1.0,1.0,1.0},{1.0,0.0,0.0,1.0},{0.10,0.0,0.0,1.0} }; GLfloat specular[][4]= { {1.0,1.0,1.0,1.0},{1.0,0.0,0.0,1.0},{0.99,0.0,0.0,1.0} }; GLfloat position[][4]={ {0.0,10.0,0.0,0.0},{2.0,2.0,0.0,1.0},{2.0,2.0,0.0,1.0} };
display()
, after the call to setCamera()
.
void setLights(){ int i, light=whiteLight; for(i=GL_LIGHT0;i<=GL_LIGHT2;i++){ glLightfv(i,GL_POSITION,position[light]); glLightfv(i,GL_AMBIENT, ambient[light]); glLightfv(i,GL_DIFFUSE, diffuse[light]); glLightfv(i,GL_SPECULAR,specular[light++]); } }
/* manage materials */ enum{whiteMaterial}; GLfloat mAmbient[][4]={ {0.4,0.4,0.3,1} }; GLfloat mDiffuse[][4]={ {0.5,0.5,0.5,1} }; GLfloat mSpecular[][4]={ {0.6,0.6,0.5,1} }; GLfloat mShine[]={ 25 }; int current=whiteMaterial;
void setMaterial(){ glMaterialfv(GL_FRONT,GL_AMBIENT,mAmbient[current]); glMaterialfv(GL_FRONT,GL_DIFFUSE,mDiffuse[current]); glMaterialfv(GL_FRONT,GL_SPECULAR,mSpecular[current]); glMaterialf(GL_FRONT,GL_SHININESS,mShine[current]); }
display()
(after the call to set the lights).