Archived

This topic is now archived and is closed to further replies.

wiek

lighting objects retrieved from a display list

Recommended Posts

Hi everyone, Can someone please help me out here...? Using the wonderful tutorials from this site I''ve been trying to create a car-driving game. I create the cars in separate display lists, so I can retrieve a complete car and put it anywhere on the track. The problem is that these objects are all rotated in different ways later on (so I call glLoadIdentity, translate, rotate etc. in my scene drawing code) but the lighting seem to be fixed for each object, relative to the object. In other words, when I retrieve a object from a display list and rotate the object 360 degrees in front of the camera, the light seems to rotate with the car, not stay fixed in the world as the camera does. Now I have all these objects which are lighted from the same angle (relative to the object) even though they face another direction in the world. Could it be that once a display list has been created, the object always gets the light from the same direction ? That seems weird to me. What am I doing wrong here ? I create the light at initgl, only once.

Share this post


Link to post
Share on other sites
i had the same problem. what i did was i found out that before placing the light positions in the scene,i had to switch to modelspace.

glMatrixMode(GL_MODELVIEW);

that made it all better..

a2k

Share this post


Link to post
Share on other sites
Yes, the light is rotated/translated with the scene, so you will have to define the lights more than once in the initgl function. You might try in your renderscene function to make the light be postitioned differently depending on the rotation angle, but i''m sure there''s an easier way....

S.

Share this post


Link to post
Share on other sites
Tried that, doesn''t work unfortunately.....

quote:
Original post by a2k

i had the same problem. what i did was i found out that before placing the light positions in the scene,i had to switch to modelspace.

glMatrixMode(GL_MODELVIEW);

that made it all better..

a2k


Share this post


Link to post
Share on other sites
try what all the other guys said, too. i think what they''re gettin at is that you have to redefine the light position every time in the game loop.

oh, and by setting the matrix mode, i mean, that you set the matrix mode immediately before the light transformation, not some other matrix, but you already knew that.

oh, and don''t define lights in the display list, but you already knew that one too.

a2k

Share this post


Link to post
Share on other sites
quote:
Original post by a2k

try what all the other guys said, too. i think what they''re gettin at is that you have to redefine the light position every time in the game loop.



If I set the light in the beginning of the drawing-loop each time, nothing changes. I''m afraid it must be something stupid I''ve done wrong or something. I can''t imagine you have to redefine a light each time you''ve transformed an object. (just to be sure, I''ve tried that too, didn''t work).

All I do in the display list is:
define the list
glnewlist, lstcompile
enable depthtest
glbegin bmQuads
..
..
glend
glendlist
That''s it !
I build the lists after I define the lights...so I guess that can''t be it either....
I don''t get it....
Does it have to do something with the fact that the objects are textured ?

Thanks for your time,

Wiek


Share this post


Link to post
Share on other sites
Try this...
Say you where to place a single object and a light every frame:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Do camera transformations here to get the view right.

GLfloat lightPosition[] = { lightX, lightY, lightZ, 1.0f };
glLightfv(GL_LIGHT1, GL_POSITION, lightPosition);

//Do object transformations here:
glCallList(objectList);

I think that should work to keep your lights in one place in your world. Expand this for more objects etc.

Share this post


Link to post
Share on other sites
Oops...

My face is red with shame.......
It seems that I made a real stupid mistake in the object-importer I created earlier on. I switched x y and z when creating the polygons but forgot to do the same with the normals. The result was that the normals where all wrong. That made teh lighting seem fixed to the object...
Sorry everybody for wasting your time.....
my apologies,

Wiek

Share this post


Link to post
Share on other sites