Damiii
Damiii

Reputation: 1373

What's the difference between gllight and glulookat (depending the order)

I would like to know what is the difference between:

glLightfv(GL_LIGHT0, GL_POSITION, pos);
gluLookAt(...)

and

gluLookAt(...)
glLightfv(GL_LIGHT0, GL_POSITION, pos);

Because for me, it looks pretty the same (unless the order of instructions)

Upvotes: 0

Views: 562

Answers (1)

derhass
derhass

Reputation: 45332

lThe light position vector will by transformed using the current GL_MODELVIEW matrix at the time of the glLighttv() call to get the eye-space position of the light source, which is used for the lighting calculations when rendering the primitives. So the order of these operations does matter.

YOur code snippets are very small. Let's assume the current modelview matrix is just identity. In this case, the first varian would lead to the light position being directly set in eye-space. So the light source actually moves when the camera moves, the relative position of the light and the camera always stays the same.

The latter variant would set the light position according to the current view matrix set by gluLookAt(). If you move the camera, the relative positions of light and camera would change, the resulting effect would be that the light has a stable world space position, e.g. you could actually move near the light source.

Upvotes: 2

Related Questions