# gl_lighting problem

This topic is 4737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been working with the basic GL_LIGHTING lights in a first person game. The problem I'm having is that the lights reach forever. I set attenuation (with various combinations) but everything that should be out of reach of the light source (whose origin is the player) can still be seen slightly, no matter how far away. Those areas far enough away should be entirely pitch black. Am I doing something stupid, or are the ogl lights stupid? ...oh by the way, I'm not setting any materials for anything in my program. Thanks! ~Mark

##### Share on other sites
A call to glLightModel*() can set your lights to shine an infinite or local distance away. To set your lights to shine a finite distance (locally), call it like this:

glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

Anywhere in your initialization setup should be fine (definitely not during your rendering loop, unless you want some objects to be lit at infinite distances and others not, but I'm not sure if that would work). The second parameter there is the flag for setting local or infinite lights. True = local (what it sounds like you want), false = infinite. According to the redbook, infinite is the default.

Hope that helps!

##### Share on other sites
No, GL_LIGHT_MODEL_LOCAL_VIEWER just sets whether you want to assume an infinite viewpoint or not for specular calculations, it has nothing to do with attenuation or the distance a light shines.

I think what you're probably seeing is the default light model ambient value (which is (0.2, 0.2, 0.2, 1.0)). To change that to zero do something like this...
GLfloat ambient[4] = {0.0f, 0.0f, 0.0f, 1.0f};glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
Let us know if that is the problem. If that's not it, post some "relevant" code.

##### Share on other sites
Quote:
 Original post by KalidorNo, GL_LIGHT_MODEL_LOCAL_VIEWER just sets whether you want to assume an infinite viewpoint or not for specular calculations, it has nothing to do with attenuation or the distance a light shines.

Just checked the redbook and you're absolutely right. My bad. I'd check the ambient component of your lights, then, as Kalidor said.

Thanks for the correction, Kalidor.

##### Share on other sites
ah great! Setting the (global?) ambient color to black worked! Thanks!
~Mark

• 23
• 10
• 19
• 15
• 14