Skip to main content
GameDev.net gamedev.net
🔒 Locked

adding multiple lights to scene, dynamically

Started by FreJa Dec 10, 2008 at 6:19 AM 2 replies 650+ views
Original Post
FreJa
FreJa
Hey, First of, I'm not using shaders. My ogl scene is described through a text file where I type the different scene elements (as a map). One of these elements is lighting, and so, I want to be able to do something like:

light point 1.0 1.0 1.0  1.0 0.0 0.0  1.0 1.0 1.0 
light point 1.0 1.0 1.0  0.0 1.0 0.0  1.0 1.0 1.0
this would create two point lights in my scene. My problem is how I "convert" this to code, I mean, is there any way to dynamically create lights, or do I always have to see how many lights to I have and just call GL_LIGHT0, GL_LIGHT1, and so on? Any other suggestions? Thanks!
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
V-man
V-man
You can enable a light whenever you want and setup properties with calls to glLight. You can even apply like 2 lights to some polygons and 1 lights to some other one

glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
DrawThing();

glDisable(GL_LIGHT1);
DrawThing2();

It's up to you to read the text file. OpenGL just does graphics. It's for sending commands to the GPU.
FreJa
FreJa
Quote:
Original post by V-man
You can enable a light whenever you want and setup properties with calls to glLight. You can even apply like 2 lights to some polygons and 1 lights to some other one

glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
DrawThing();

glDisable(GL_LIGHT1);
DrawThing2();

It's up to you to read the text file. OpenGL just does graphics. It's for sending commands to the GPU.


Right, I know that. I didn't explain very well.
My problem is in setting the properties for each light, using glLightfv, for example, which takes, as first argument the light id (GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, and so on). The problem is I don't know how many lights I'll have, so how do I pass that first argument? Do I repeat code for eevery light I have?...

Thanks again!
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
CableGuy
CableGuy
You can set the first light you encounter to have id of GL_LIGHT0 the next one GL_LIGHT1 and so on. I really don't get your problem here. can you elaborate a bit more?
Also remember that GL_LIGHTn is guaranteed to be equal to GL_LIGHT0 + n.

HTH.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.