Help with Lighting in OGL

Started by
8 comments, last by zaNeXuS 21 years, 11 months ago
I got this big problem in OpenGl on LightSources.I''ve got this world full of objects, I then put in a Positional LightSource, which acts almost like a sun. Then I move around with gluLookAt.When I move to a face which doesn''t face the sun and is obviously darker, I then turn the cam to the face and then the face suddenly lights up as if I was the LightSource... What''s going on plz Help me. Thanx alot!!! Gaming is Life
---------------Gaming is Life---------------
Advertisement
So no one here know what my problem is? wow.....

|--------------|
|Gaming is Life|
|--------------|
---------------Gaming is Life---------------
Some possibilities:

Is your glLight... call in the wrong place? It should be just after your camera transform.

Have you mistakenly put your camera transform in the projection matrix instead of the modelview?


If that doesn't help, post the relevant code and I'll take a look.

____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on May 2, 2002 6:44:25 PM]

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Like Ben says, watch where you put that light, it should be treated just like a regular 3d object, placed in modelview.

What you have is the "miner''s hat" light, cool if that is what you want.

zin

zintel.com - 3d graphics & more or less
zintel.com - 3d graphics & more or less
OK.. I did what u guys mentioned. My Camera is done in MODELVIEW.
All vertices have their proper normals given. GL_LIGHTING enabled.GL_LIGHT0 enabled.(I only have the one light)...
SHould I now enable the each time after I call gluLookAt?
Well'' I tried that and tried calling it before gluLookAt each time.Same result .
I will try and put all the code together in a way to understand, but it''ll be pretty difficult as each part is linked to other class objects...Starting on it tonight though.

|---------------|
|Gaming is Life|
|---------------|
---------------Gaming is Life---------------
OK.. I did what u guys mentioned. My Camera is done in MODELVIEW.
All vertices have their proper normals given. GL_LIGHTING enabled.GL_LIGHT0 enabled.(I only have the one light)...
SHould I now enable the each time after I call gluLookAt?
Well'' I tried that and tried calling it before gluLookAt each time.Same result .
I will try and put all the code together in a way to understand, but it''ll be pretty difficult as each part is linked to other class objects...Starting on it tonight though.

|---------------|
|Gaming is Life|
|---------------|
---------------Gaming is Life---------------
You only need to enable the light once, but you need to put a call to glLightfv immediately after the gluLookAt call

glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

where lightpos is an array of 4 floats, containing the light''s position and lightpos[3] is 1.0 (which specifies the light is positional)

Let me know if that works

____________________________________________________________
www.elf-stone.com

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

!!!!!!!!!!! Thanx alot Ben. It''s working perfectly. Now my world Looks right.
p.s. - The directional light type: Is that always where the cam is positioned ?

|---------------|
|Gaming is Life|
|---------------|
---------------Gaming is Life---------------
No. If you specify a directional light, you''re specifying a light an infinite distance from the viewer (like the Sun, in effect). The first 3 floats in that case are the normal vector. Look up glLightfv for more info.

____________________________________________________________
www.elf-stone.com

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

OK I will, thx alot for the help.

---------------
Gaming is Life
---------------
---------------Gaming is Life---------------

This topic is closed to new replies.

Advertisement