Light Problem

In my program i load a DXF model, create a directional light and a camera, and move/rotate/translate/scale each of them.
My problem is that the objects are positioned well, but are lit as if they still were in the origin, and not relative to their real position.

This is the code of the rendeing part:

el=list;
while (el)
{
if (!el->specialFlag)
{
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_NORMALIZE);
glLoadMatrixf(el->matrix);
glNormalPointer(GL_FLOAT,0,el->normalArray);
glVertexPointer(3,GL_FLOAT,0,el->vertArray);
glDrawArrays(el->type,0,(GLsizei)el->vertArrayCur/3);
}
el=el->next;
}

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glLoadIdentity();
el=list;
while (el)
{
if (el->specialFlag==POINTLIGHT)
{
for (i=0;i<4;i++)
lightPos[i]=el->lightPos[i];
multMatrVect(el->matrix,lightPos);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
}
el=el->next;
}

(el->matrix holds the tranform matrix associated with that element;
el->specialFlag is 0 for objects, and !=0 for camera and light)

mmm, I have the same problem if I move the object and not the light: the illumination doesn’t change

Remember that light positions are transformed with the MODELVIEW matrix exactly like the rest of geometry. You may need to push/pop the matrix stack for the lights in order to not transform them with the geometry.

The problem is when i move the object: the light is not moved, but the object is lit as if it was still in the origin.
I tried with some glPushMAtrix and glPopMatrix, but it didn’t help

try this:

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

// put the light definitions here

glPopMatrix();

It doesn’t work.
it seems to me that openGL applies the lighting to the object centered in the origin, and then places it in the real position.

Are you by chance using a directional light?

You don’t show what values you are using for GL_POSITION, but if you are setting the 4th number in the array to 0 (or worse yet, only have 3 components in the array) you will have a directional light, not a positional light.

Example:

float lightpos1[4] = {0.0, 0.0, 1.0, 0.0}; // directional
float lightpos2[4] = {0.0, 0.0, 1.0, 1.0}; // positional

YESSSSSS!!!
THANK YOU SO MUCH!!!
I’M SOOOO DUMB!!!
I tried doing a thousand changes except that fourth parameter which i left to 0.0!
I didn’t understand well the difference between a spot and a directional light
THANK YOU SO MUCH!

Ahhhhhhh, it’s always nice to see new error-symptoms nice it’s solved now, and sorry for my stupidity.