Original Post
Hello all, I'm trying to use lights and materials in opengl. here is the code for the initialization:
Thanks for any advice
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
float dif[]={1.0f,1.0f,1.0f,1.0f};
float amb[]={0.5f,0.5f,0.5f,1.0f};
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0,GL_POSITION,lpos);
glLightfv(GL_LIGHT0,GL_AMBIENT,amb);
glLightfv(GL_LIGHT0,GL_DIFFUSE,dif);
glEnable(GL_LIGHT0);
and for the scene:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glLightfv(GL_LIGHT0,GL_POSITION,lpos);
glTranslatef(0.0f,0.0f,-6.0f);
float dif[]={1.0f,0.0f,0.0f};
glMaterialfv(GL_FRONT,GL_DIFFUSE,dif);
GLUquadric *q=gluNewQuadric();
gluQuadricNormals(q,GL_SMOOTH);
gluSphere(q,1.0f,64,64);
glDisable(GL_LIGHTING);
glTranslatef(lpos[0],lpos[1],lpos[2]);
glColor3f(1.0f,1.0f,0.0f);
gluSphere(q,0.1f,8,8);
glEnable(GL_LIGHTING);
when I position the light inside the sphere,the outer faces get colored.Is that normal or if it's not,could anyone tell me what's wrong?
Thanks for any advice