Microsoft DirectX 8.0 (Visual Basic)

Setting Light Properties

Your Microsoft Visual Basic® application sets lighting properties by preparing a D3DLIGHT8 type and then calling the Direct3DDevice8.SetLight method. The SetLight method accepts the index at which the device should place the set of light properties to its internal list of light properties, and the address of a prepared D3DLIGHT8 type that defines those properties. You can call SetLight with new information as needed to update the light's illumination properties.

The system allocates memory to accommodate a set of lighting properties each time you call the SetLight method with an index that has never had properties assigned. Applications can set a number of lights, with only a subset of the assigned lights enabled at a time. Check the MaxActiveLights member of the D3DCAPS8 type when you retrieve device capabilities to determine the maximum number of active lights supported by that device. If you no longer need a light, you can disable it or overwrite it with a new set of light properties.

The following code example prepares and sets properties for a white point-light whose emitted light will not attenuate over distance.

'
' For this example, the d3dDevice variable contains a valid reference
' to a Direct3DDevice8 object.
'
Dim LightDesc As D3DLIGHT8
Dim c As D3DCOLORVALUE
Dim vPos As D3DVECTOR

' Use the same color settings for all emitted light color.
With c
    .r = 1#: .g = 1#: .b = 1#
    .a = 1# ' The alpha component isn't used for lights.
End With

With vPos
    .x = 0: .y = 1000: .z = -100
End With

With LightDesc
    .Type = D3DLIGHT_POINT
    .Position = vPos
    .Ambient = c: .diffuse = c: .specular = c
    .Attenuation0 = 1# ' Don't attenuate the light
End With

d3dDevice.SetLight 0, LightDesc

You can update a set of light properties with another call to SetLight at any time. Specify the index of the set of light properties to update and the D3DLIGHT8 type that contains the new properties.

Note  Assigning a set of light properties to the device does not enable the light source whose properties are being added. Enable a light source by calling the Direct3DDevice8.LightEnable method for the device.