light position parameters

Greetings,

I have a small query, when setting the position of a light source:

e.g.
float[] lightPosition = {0.0f, 5.0f, 5.0f, 0.0f};
gl.glLightfv(GL11.GL_LIGHT0, GL11.GL_POSITION, lightPosition, 0);

I see it takes an array of four values - why is this? I assume you are passing a position or direction (x, y, z, ?).

Hopefully someone can enlightening me.

Cheers,
James

The fourth component of the array determines the light type. There are two primary types of lights in opengl: direction lights and spot lights (or point light depending on certain parameters). If the fourth component is 0, then the light is at infinity in the direction of x, y, z (1st 3 coords). Any other value causes the light to be treated as a spot/point light with the fourth coord used as normal with any other coord type. Generally for spot lights, you’ll want to use a value of 1.

There is some confusion with the interpretation of the direction light’s position parameter. It is the direction to the light, not the direction the light is shining. Lastly the position and direction parameters for a light are transformed by the currently set modelview matrix, so you want to make sure that you setup your matrices and lights in the desired order.

Thank you that is exactly what I wanted to know :slight_smile: