Share via


Setting Material Properties

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

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

Set the material properties that the system uses by preparing a D3DMMATERIAL structure, and then calling the IDirect3DMobileDevice::SetMaterial method.

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

D3DMMATERIAL mat;

// Set the RGBA for diffuse reflection.
mat.Diffuse.r = 0.5f;
mat.Diffuse.g = 0.0f;
mat.Diffuse.b = 0.5f;
mat.Diffuse.a = 1.0f;

// Set the RGBA for ambient reflection.
mat.Ambient.r = 0.5f;
mat.Ambient.g = 0.0f;
mat.Ambient.b = 0.5f;
mat.Ambient.a = 1.0f;

// Set the color and sharpness of specular highlights.
mat.Specular.r = 1.0f;
mat.Specular.g = 1.0f;
mat.Specular.b = 1.0f;
mat.Specular.a = 1.0f;
mat.Power = 50.0f;

After preparing the D3DMMATERIAL structure, you apply the properties by calling the IDirect3DMobileDevice::SetMaterial method of the rendering device. This method accepts the address of a prepared D3DMMATERIAL structure 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 pd3dmDev is assumed
// to be a valid pointer to an IDirect3DMobileDevice interface.
HRESULT hr;
hr = pd3dmDev->SetMaterial(&mat, D3DMFMT_D3DMVALUE_FLOAT);
if(FAILED(hr))
{
    // Code to handle the error goes here.
}

When you create a Direct3D Mobile 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)

Power

(0.0)

See Also

Concepts

Materials