Reflections
Adding reflections to a too can improve it realism to a great extent. Here we'll look at a simple method to create reflection where we simply redraw the object with a appropriate Transformati On and make the surface in between translucent. This is creates an effective illusion of reflection!!
1, set the light source code to modify the following:
void Ccy457openglview::setuplighting ()
{
Material Properties
Glfloat matspecular[] = {1.0f, 0.0f, 0.0f, 0.7f};
Glfloat matshininess[] = {50.0f};
Glfloat matambient[] = {0.25f, 0.25f, 0.25f, 0.7f};
Glfloat matdiffuse[] = {0.5f, 0.5f, 0.5f, 0.7f};
GLMATERIALFV (Gl_front, Gl_specular, matspecular);
GLMATERIALFV (Gl_front, gl_shininess, matshininess);
GLMATERIALFV (Gl_front, Gl_diffuse, Matdiffuse);
GLMATERIALFV (Gl_front, gl_ambient, matambient);
Lighting Parameters
Enable Lighting
Glenable (gl_lighting);
Specify a single directional light
Glfloat ambient1[] = {0.5f,0.5f,0.5f};
Glfloat diffuse1[] = {0.5f,0.5f,0.5f};
Glfloat specular1[] = {1.0f,0.0f,0.0f};
Glfloat position1[] = {0.0f,0.0f,5.0f,0.0};
GLLIGHTFV (Gl_light0, gl_ambient, ambient1);
GLLIGHTFV (Gl_light0, Gl_diffuse, diffuse1);
GLLIGHTFV (Gl_light0, Gl_specular, specular1);
GLLIGHTFV (Gl_light0, gl_position, Position1);
Glenable (GL_LIGHT0);
Specify a single positional spotlight
Glfloat ambient2[] = {1.0f,1.0f,0.0f};
Glfloat diffuse2[] = {1.0f,0.0f,0.0f};
Glfloat position2[] = {1.0f,0.0f,5.0f,1.0};
Glfloat direction2[] = {0.0f,0.0f,-5.0f};
GLLIGHTFV (gl_light1, gl_ambient, Ambient2);
GLLIGHTFV (gl_light1, Gl_diffuse, DIFFUSE2);
GLLIGHTFV (gl_light1, gl_position, Position2);
GLLIGHTFV (gl_light1, gl_spot_direction, Direction2);
GLLIGHTF (gl_light1, Gl_spot_cutoff, 15.0f);
Glenable (GL_LIGHT1);
}