Hello , I am trying to create room where outside light wont effect the light inside the room .
So my first thing to do was to get this result (the light is enabled only when walls are drawing):
When drawing the walls I ensure that the normal vectors are pointing to room center.
To avoid light effect outside side of meshes I am using :
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE ,GL_TRUE);
GL_LIGHT_MODEL_TWO_SIDE should enable light on both sides of mesh , why its acting as inverse effect ?
If I disable this effect , note using GL_LIGHT_MODEL_TWO_SIDE true I get this :
Then I want to try add another light which is located outside of center of room roof,But wait … the outside light wont effect the meshes outside the room because all the normal’s are pointing to center of room .
So I must disable GL_LIGHT_MODEL_TWO_SIDE … because I need light on both sides of mesh .
But the thing is that now the outside light effect the inside light :
How do I achieve the goal I need ? How to configure lights and normal’s on meshes so they will be on both sides of polygon and react to the light which is closer to them , because now as you can see the light goes trough walls :dejection:?
I am also using GL_FRONT_AND_BACK
Here is the configurations before painting :
void display()
{
// clears the buffers with color set in initGraphics with glClearColor
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(LEFT,RIGHT,BOTTOM,TOP,NEAR,FAR);
gluLookAt(eyeX,eyeY,eyeZ,eyeLookAtX,eyeLookAtY,eyeLookAtZ,headX,headY,headZ);
drawFloor();
drawGrid();
drawAxis();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_AMBIENT_AND_DIFFUSE);
//glLightModelf(GL_LIGHT_MODEL_TWO_SIDE ,GL_TRUE);
//glEnable(GL_NORMALIZE);
glLightfv(GL_LIGHT0,GL_AMBIENT,l0amb);
glLightfv(GL_LIGHT0,GL_DIFFUSE,l0diff);
glLightfv(GL_LIGHT0,GL_SPECULAR,l0spec);
glLightfv(GL_LIGHT0,GL_POSITION,l0pos);
glLightfv(GL_LIGHT1,GL_AMBIENT,l1amb);
glLightfv(GL_LIGHT1,GL_DIFFUSE,l1diff);
glLightfv(GL_LIGHT1,GL_SPECULAR,l1spec);
glLightfv(GL_LIGHT1,GL_POSITION,l1pos);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,m0amb);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,m0diff);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,m0spec);
glMaterialf (GL_FRONT_AND_BACK,GL_SHININESS,30);
drawRoom....
}