DirectX SDK

Retrieving Light Properties

[C++]

You can retrieve all the properties for an existing light source from C++ by calling the IDirect3DDevice7::GetLight method for the device. When calling the GetLight method, pass in the first parameter the zero-based index of the light source for which the properties will be retrieved, and supply the address of a D3DLIGHT7 structure in the second parameter. The device will fill the D3DLIGHT7 structure to describe the lighting properties it uses for the light source at that index.

The following C++ code illustrates this process:

    /*
     * For the purposes of this example, the g_lpd3dDev variable
     * is a valid pointer to an IDirect3DDevice7 interface.
     */
    HRESULT hr;
    D3DLIGHT7 light;
    
    // Get the property info for the first light.
    hr = g_lpd3dDev->GetLight(0, light);
    if (FAILED(hr))
    {
// Code to handle the error goes here.
    }

If you supply an index outside the range of the light sources assigned within the device, the GetLight method will fail, returning DDERR_INVALIDPARAMS.

[Visual Basic]

A Visual Basic application retrieves the properties for an existing light source by calling the Direct3DDevice7.GetLight method for the device. When calling the GetLight method, pass in the first parameter the zero-based index of the light source for which the properties will be retrieved, and a variable of type D3DLIGHT7 as the second parameter. The device will fill the D3DLIGHT7 type to describe the lighting properties it uses for the light source at that index.

The following Visual Basic code fragment illustrates this process:

'
' For the purposes of this example, the d3dDevice variable contains
' a valid reference to a Direct3DDevice7 object.
'
Dim lightDesc As D3DLIGHT7

' Get the property info for the first light.
Call d3dDevice.GetLight(0, lightDesc)
If Err.Number <> DD_OK Then
    ' Code to handle the error goes here.
End If

If you supply an index outside the range of the light sources assigned within the device, the GetLight method will fail, and the value of Err.Number will be DDERR_INVALIDPARAMS.