Microsoft DirectX 8.0 (Visual Basic)

Setting Material Properties

Microsoft® Direct3D® rendering devices can render with one set of material properties at a time.

In a Microsoft® Visual Basic® application, set the material properties that the system uses by preparing a D3DMATERIAL8 type, then calling the Direct3DDevice8.SetMaterial method.

To prepare the D3DMATERIAL8 type for use, set the property information in the structure to create the desired effect during rendering. The following code example sets up the D3DMATERIAL8 type for a purple material with sharp white specular highlights.

Dim mat As D3DMATERIAL8

' Set the RGBA for diffuse reflection.
mat.diffuse.r = 0.5
mat.diffuse.g = 0#
mat.diffuse.b = 0.5
mat.diffuse.a = 1#

' Set the RGBA for ambient reflection.
mat.ambient.r = 0.5
mat.ambient.g = 0#
mat.ambient.b = 0.5
mat.ambient.a = 1#
 
' Set the color and sharpness of specular highlights.
mat.specular.r = 1#
mat.specular.g = 1#
mat.specular.b = 1#
mat.specular.a = 1#
mat.power = 50#

After preparing the D3DMATERIAL8 type, apply the properties by calling the Direct3DDevice8.SetMaterial method of the rendering device. This method accepts the address of a prepared D3DMATERIAL8 type as its only parameter. You can call SetMaterial with new information as needed to update the material properties for the device. The following code example shows how this might look in code.

' This code example uses the material properties defined for
' the mat variable earlier in this topic. The d3dDevice is 
' assumed to contain a valid reference to a Direct3DDevice8 
' object.
On Local Error Resume Next

Call d3dDevice.SetMaterial(mat)
If Err.Number <> D3D_OK Then
    ' Code to handle the error goes here.
End If

When you create a Direct3D device, the current material is automatically set to the default shown in the following table.

Member Value
Diffuse (R:1, G:1, B:1, A:0)
Specular (R:0, G:0, B:0, A:0)
Ambient (R:0, G:0, B:0, A:0)
Emissive (R:0, G:0, B:0, A:0)
Power (0.0)