This is our lighting and materials model.
Our application is structured in this manner: the file model.cpp contains the geometry model and the file scene.cpp contains the rendering function.
In the model file (model.cpp) we specify materials as global arrays, then we put together with vertexes position, normals in a display list.
In the render scene file (scene.cpp) we activate light (glEnable(GL_LIGHTING)) and specify a single global light
float lightDir[] = {0.0f, 0.0f, 10.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_POSITION, lightDir);
glEnable(GL_LIGHT0);
Each time we redraw the scene we call the GLCallList(ObjectList).
The animation consist of redrawing the whole scene with a frame rate of 20 frame/sec
an example of (file model.cpp)
GLfloat white_plastic_ambient[] =
{0.33, 0.22, 0.03, 1.0}, white_plastic_diffuse[] =
{0.50, 0.50, 0.50, 1.0}, white_plastic_specular[] =
{0.90, 0.90, 0.80, 1.0}, white_plastic_shininess[] = {60.0};
ObjectModel :: ObjectModel(){
//[…code omitted…]
glNewList(ObjectList, GL_COMPILE);
glLightfv(GL_LIGHT0, GL_AMBIENT, white_plastic_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, white_plastic_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, white_plastic_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, white_plastic_shininess);
glRotated(72, 1.0, 0.0, 0.0);
glRotated(90, 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
for (int i = 0; i < numSectors; ++i) {
double angle1 = (i * 2 * Pi) / numSectors;
GLdouble x5 = alpha_1 * sin(angle1);
GLdouble y5 = alpha_1 * cos(angle1);
GLdouble x6 = alpha_2 * sin(angle1);
GLdouble y6 = alpha_2 * cos(angle1);
double angle2 = ((i + 1) * 2 * Pi) / numSectors;
GLdouble x7 = alpha_2 * sin(angle2);
GLdouble y7 = alpha_2 * cos(angle2);
GLdouble x8 = alpha_1 * sin(angle2);
GLdouble y8 = alpha_1 * cos(angle2);
quad(x8, y8, x7, y7, x6, y6, x5, y5); // Function for calculate our model.
}
glEnd();
glEndList();
} // end of the constructor
Many thanks, Francesco.