Question on how lighting works in OpenGL

Hi everyone,

I’ve been learning how to code OpenGL (ES to be exact, for Android platform) for the past couple of weeks. I’ve bumped into a problem and I am unable to progress any further at the moment. I’d appreciate if someone can suggest what I’m doing wrong here.

I’ve drawn couple of walls here. The goal was to draw walls with spot lights so that I can see the “ring” of lights. Although I had a tunnel working with just 2 triangles per wall, I realized there just isn’t enough vertices to create a realistic spot light, so I went further from here.

This is what I’ve done so far:

  1. I’ve created a basic wall that contains 5x5 squares which in turn are made out of 2 triangles. Since this is going to be a tunnel, I’ve assigned normal vectors at each vertices to be (1,0,0) for the “left” wall.

  2. I’ve used translations and rotations to create more walls.

  3. I’ve placed the light source on top of the bottom surface, facing (-1, 0, 0). I am expecting a circular light pattern on the left wall and no other walls.

Here’s the link to the render:

Explanation of what you are seeing in the picture:

  1. All vertex points positions are ok - its working as intended.

  2. For some reason, all walls further than 2f from the origin shows white. Only the left wall connected to the ceiling is rendered correctly.

  3. Floor shows some weird patterns and even a hole in the middle. The light does not face in this direction at all. In fact, if I bring the lower left wall into the distance 1f, it looks identical to this floor.

Any idea what’s going on here?

Thank you.