Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
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 D3DMMATERIALstructure, and then calling the IDirect3DMobileDevice::SetMaterialmethod.

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

Copy Code
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 D3DMMATERIALstructure, you apply the properties by calling the IDirect3DMobileDevice::SetMaterialmethod of the rendering device. This method accepts the address of a prepared D3DMMATERIALstructure as its only parameter. You can call SetMaterialwith new information as needed to update the material properties for the device. The following code example shows how this might look in code.

Copy 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