[OpenGL] Light position


#1

So I’m a complete noob when it comes to OpenGL but I have experience with Direct3D. I don’t know if this is the best place for this question but I figured it was worth a try.

I’m developing a basic 3D application with a ball rolling on the ground, using the Juce OpenGLDemo example as a starting point. I managed to add keyboard controls to move/rotate the ball, the problem I’m facing is it also effects the position of the light. I’d like the light position to remain fixed but it rotates along with the ball. I know this is a shader issue since the view matrix and light position are stored in uniform values.

vec4 light = viewMatrix * lightPosition;
lightIntensity = dot (light, normal);
gl_Position = projectionMatrix * viewMatrix * position;

I’m using the “Texture + Lighting” shader included with the demo, you’ll notice the light rotates with the object in the demo as well. I tried creating a new uniform and multiplying by that instead of viewMatrix, I also tried resetting the view matrix to identity state before and after drawing the objects but neither solution worked. Shaders are like a foreign language to me they are hard to grasp.

Can someone point me in the right direction? Tom