Sign in to follow this  

Simple doubt about more than one light in the scene

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this