Weird Lighting-Problem

Hi!
I have added a light to my scene, but the lighting only works, if the light is located at 0,0,0…if i move my light, my objects just don´t get lit.
Why?? Shouldn´t the objects just get lit in a diffrent way?? But lighting just seems to be off…Please help!

Make sure you call glLightfv(GL_LIGHT0, GL_POSITION, pos) every frame.

Old GLman

Post the code where you are using the light for see it.

Sorry, I can´t post the code…it would be too much and it´s in a lot of diffrent classes and functions etc.
But my problem even got more weird. When I look around in my scene, sometimes my objects ar lit correctly, but then, when camera has a special angle, the colors get changed and sometimes my whole scene is just drawn in black/white…also my cursor gets white (before it was black). When I look back it´s black again and the other colors appear correctly

This sounds completely whacked. You have some serious problems that could be the result of many things. Try simplifying things. Check your normals, check your light position values and watch where you apply it (hopefully after view transformation but before model transformation).

Some of your issues sound like you are positioning the light before the viewing matrix transformation has been loaded onto the modelview stack.

You need to understand the difference between positioning the light attached to the viewer, positioning the light in the scene and positioning it attached to an object. It all depends on what’s on the modelview at the time.

P.S. make sure that you are specifying the correct type of light with the fourth coordinate i.e. point light vs light vector. I assume you want a point source since you specify a position of 0,0,0. So you need to specify a position of 0,0,0,1 where the fourth coordinate w is one not zero. The one means you have a point light vs a directional (distant) light. Specifying a light position of 0,0,0,0 would be a very nasty thing to do and may explain many of your problems.

Ah!!! That was it!!!
I always called:

  GLfloat  lightpos[3];
  lightpos[0]=light_x;
  lightpos[1]=light_y;
  lightpos[2]=light_z;
  glLightfv(GL_LIGHT0,GL_POSITION,lightpos);

So i added a fourth coordinate with 1.0f and it works as it should!!! :slight_smile:
Maybe the arrays pointed some weird data…