• 15
• 15
• 11
• 9
• 10

# Simple doubt about more than one light in the scene

This topic is 4456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I would to add more than one light in my scene, but I am a bit confused on how to proceed... Suppose, for example, that I want to add 3 lights in my scene. Would it be wrong call the following function 3 times?
// Just an exemple...
VOID Lighting( "pass the device, light's position, light's range etc..." )
{
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));

light.Type = ...;
light.Diffuse.r  = ...;
light.Diffuse.g  = ...;
light.Diffuse.b  = ...;
light.Ambient.r  = ...;
light.Ambient.g  = ...;
light.Ambient.b  = ...;
light.Specular.r = ...;
light.Specular.g = ...;

light.Specular.b = ...;
light.Position.x = ...;
light.Position.y = ...;
light.Position.z = ...;

light.Attenuation0 = ...;
light.Range        = ...;

pDevice->SetLight(0, &light);
pDevice->LightEnable(0, TRUE);
}

Do I need to change the index values in SetLight and LightEnable methods, for each light? Thanks in advance

##### Share on other sites
The first parameter of SetLight and LightEnable specifies which light. If you leave the parameter at 0, then you are only affecting one light -- light 0. If you want 3 lights then you have to specify 3 different lights, (e.g. 0, 1, and 2).

##### Share on other sites
Quote:
 Would it be wrong call the following function 3 times?

Nope, not at all.. but there are easier ways to not have to duplicate code.
You could create methods that will create a light for you and place it in a collection.
What I normally do is have an array of lights and this is how I managed individual lights in the fixed function pipeline.
Then for each light you will set it to the device.
e.g.
IDirect3DDevice9::SetLight(lightNumber, &light[lightNumber]);

I hope this helps.
Take care.