Platform SDK: DirectX

Enabling and Disabling Lights

[C++]

Once you assign a set of light properties for a light source in a scene, the light source can be activated by calling the IDirect3DDevice7::LightEnable method for the device. New light sources are disabled by default. The LightEnable method accepts two parameters. Set the first parameter to the zero-based index of the light source to be affected by the method, and set the second parameter to TRUE to enable the light or FALSE to disable it.

The following code fragment illustrates the use of this method by enabling the first light source in the device's list of light source properties.

/*
 * For the purposes of this example, the g_lpd3dDev variable
 * is a valid pointer to an IDirect3DDevice7 interface.
 */
HRESULT hr;

hr = g_lpd3dDev->LightEnable(0, TRUE);
if (FAILED(hr))
{
    // Code to handle the error goes here.
}
[Visual Basic]

Once you assign a set of light properties for a light source in a scene, the light source can be activated by calling the Direct3DDevice7.LightEnable method for the device. New light sources are disabled by default. The LightEnable method accepts two parameters. Set the first parameter to the zero-based index of the light source to be affected by the method, and set the second parameter to True to enable the light or False to disable it.

The following code fragment illustrates the use of this method by enabling the first light source in the device's list of light source properties.

'
' For the purposes of this example, the d3dDevice variable contains
' a valid reference to Direct3DDevice7 object.
'
On Local Error Resume Next

Call d3dDevice.LightEnable(0, True)
If Err.Number <> DD_OK Then
    'Code to handle the error goes here.
End If

If you enable a light that has no properties, or supply an index outside the range of the light property sets assigned within the device, the LightEnable method creates a light source with the following properties and enables or disables it.

Member Default
dltType D3DLIGHT_DIRECTIONAL
dcvDiffuse (R:1, G:1, B:1, A:0)
dcvSpecular (R:0, G:0, B:0, A:0)
dcvAmbient (R:0, G:0, B:0, A:0)
dvPosition (0, 0, 0)
dvDirection (0, 0, 1)
dvRange 0
dvFalloff 0
dvAttenuation0 0
dvAttenuation1 0
dvAttenuation2 0
dvTheta 0
dvPhi 0