Hi citizen and sebb,
Thanx for the early reply…
But I my problem is still unsolved .
I have enabled both the openGL lighting capability and GL_LIGHT0.
But I have not specified glLightModel assuming the default value which
takes the viewer at infinite position.
Also the material properties are specified correctly. Since normals are of unit length,
so there is no need to normalize them.
I ll be grateful if you kindly look at this code. Here it is.
void Test ()
{
/// different light positions
GLfloat position [][4] =
{
{ 0, 170, 0, 1 }, // top of the object
{ 0, -170, 0, 1 }, // bottom of the object
{ 0, 125, 50, 1 }, // front of the object
{ 0, -125, -50, 1 }, // back of the object
{ 0, 125, 0, 1 }, // left side of the object
{ 0, 125, 0, 1, } // right side of the object
} ;
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
glEnable ( GL_DEPTH_TEST ) ;
// Settings for lighting
glShadeModel ( GL_SMOOTH ) ;
glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL ) ;
glLightModeli ( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE ) ;
//setting light properties
glLightfv ( GL_LIGHT0, GL_AMBIENT, grey ) ;
glLightfv ( GL_LIGHT0, GL_DIFFUSE, red ) ;
//setting material properties
glMaterialfv ( GL_FRONT, GL_AMBIENT, white ) ;
glMaterialfv ( GL_FRONT, GL_DIFFUSE, white ) ;
//for different positions
for ( i=0 ; i<6 ; i++ )
{
// specifying light position
glPushMatrix () ;
glLoadIdentity () ;
glLightfv ( GL_LIGHT0, GL_POSITION, position [i] ) ;
glPopMatrix () ;
// rendering cube.The rotate operation is done to see the three faces of the cube.
glPushMatrix () ;
glLoadIdentity () ;
glTranslated ( 500 + x, 125, 0 ) ;
glRotated ( 45, 1, 1, 1 ) ;
drawCuboid ( -25, -25, 0, 50, 50, 50 ) ;// This is a user defined function that draws cube at (-25, -25, 0) of lenth =50, breadth=50 and width = 50
glPopMatrix () ;
x += 75 ;
}
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_LIGHT0 ) ;
glDisable ( GL_DEPTH_TEST ) ;
}