Glenn Watson wrote:
> Hi, I am developing a room simulator in OpenGL, and am now at the stage of
> trying to get the lighting working correctly..
> The problem is, that some walls in the room appear lit correctly (bright
> near the end close to light and darker at other end of wall) while other
> walls just appear a brightish white (they are experiencing some light
> effect, but it is obvious that it is not correct as the whole wall is much
> lighter than the other walls)..
> Basically, each wall is specified by a begin X,Z and end X,Z coord with a
> constant height.. From this it is obviously possible to create a rectangular
> polygon from (beginX, height, beginZ) to (endX, -height, endZ).
> However, I know that lighting a wall with only 4 vertices would not be the
> best idea, so I use an algorithm to create 100 quads that fit into the wall
> position (10 x 10 split into the space occupied by begin->end).. I have also
> calculated surface normals for each wall (all small quads within each wall
> get the same normal direction...dodgy??), as well as applying the same
> material properties to each wall (with GL_FRONT_AND_BACK)...
> I have tried using spotlights as well as directional lights with linear
> attenuation.. but the result is the same, some walls are brightish white
> while others are lit correctly (by the way I have disabled texturing while
> trying to find this bug). I have also tried enabling / disabling two sided
> lighting, GL_NORMALIZE, and LOCAL_MODEL_VIEWER...
> It could be something to do with the light position I give perhaps... what I
> do is switch to MODELVIEW matrix and LoadIdentity() before using the call
> with GL_LIGHT_POSITION.. that happens in the initialisation of the GL widget
> and then I don't touch it again, the rendering section just clears the
> colour and depth buffer, then renders the wall and object display lists.....
> Does anyone have any other suggestions - I've run out of ideas!!!!
> PS - There is no definite pattern as to which walls are rendered
> incorrectly... it can happen whether they lie purely on the X or Z axis or
> they are on an angle... although it does seem to affect the walls furthest
> from the light (I would expect them to be dark then, not bright white!!).
> The below diagram might give a vague idea as to the pattern...
> 1 | | 7
> 2 | | 6
> +-----------+ +-----------+
> | L |
> | |
> | |
> 3 | | 5
> | |
> | |
> L = light position.. Walls 1, 7, 2 and 6 light correctly, while walls 0, 3,
> 4 and 5 appear a bright white colour..
Since you're posting to the Mesa-users list I assume that you're using
Mesa. Is that right? If so, which version? Have you tried any other
OpenGL implementations? Perhaps you've found a bug.
If you'd like me to do more I'd probably have to get a copy of your program
so that I can test for myself.