Materials

A material describes the illumination properties of a surface, including how it handles light and whether it uses a texture. You can also use a material to define the background for a viewport. You can create a material object by calling the IDirect3D2::CreateMaterial method. You can use the IDirect3DMaterial2 interface to get and set materials and to retrieve material handles.

For the ramp-mode software device, the material object keeps track of the texture map used in conjunction with the material. This enables the pre-calculation of the material palettes. When you use textures in ramp mode, you must set the D3DLIGHTSTATE_MATERIAL member of the D3DLIGHTSTATETYPE enumerated type. Once the material properties are set, a material can be associated with a device. As with textures, a material handle identifies this association of a material and a device. A material can be associated with more than one device. You retrieve a material handle by calling the IDirect3DMaterial2::GetHandle method.

The current material is a state variable in a device as part of lighting related states. Handles obtained using IDirect3DMaterial or IDirect3DMaterial2 for a given device object can be used interchangeably.

IDirect3DMaterial2 interface eliminates some unimplemented methods from the IDirect3DMaterial interface.

You can define the light-handling properties of a material in four ways:

Ambient Specifies the color of the ambient light as reflected by the material.
Diffuse Specifies the color of the diffuse light as reflected by the material. Diffuse light is light produced by one of the light sources described by the D3DLIGHTTYPE enumerated type (that is, any light except ambient light).
Specular Specifies the color of reflected highlights as produced by the material.
Emissive Specifies the color of the light that is emitted by the material.

These light-handling properties and other properties of the material, including the texture handle, are described by the D3DMATERIAL structure. You can use the D3DLIGHTSTATE_MATERIAL member of the D3DLIGHTSTATETYPE enumerated type to identify a material.

You can create an IDirect3DMaterial2 interface by calling the IDirect3D2::CreateMaterial method. The following example demonstrates how to create an IDirect3DMaterial2 interface. Then it demonstrates how to set the material and retrieve its handle by calling the IDirect3DMaterial2::SetMaterial and IDirect3DMaterial2::GetHandle methods.

lpDirect3D2->CreateMaterial(

lplpDirect3DMaterial2, // Address of a new material

pUnkOuter); // NULL

lpDirect3DMaterial2->SetMaterial(

lpD3DMat); // Address of a D3DMATERIAL structure

lpDirect3DMaterial2->GetHandle(

lpD3DDevice2, // Address of a DIRECT3DDEVICE object

lpD3DMat); // Address of a D3DMATERIAL structure