You can create an interface to a Direct3D material by calling the IDirect3D::CreateMaterial method. The following example demonstrates how to create an IDirect3DMaterial interface. Then it demonstrates how to set the material and retrieve its handle by calling the IDirect3DMaterial::SetMaterial and IDirect3DMaterial::GetHandle methods.
lpDirect3D->CreateMaterial(
lplpDirect3DMaterial, // Address of a new material
pUnkOuter); // NULL
lpDirect3DMaterial->SetMaterial(
lpD3DMat); // Address of a D3DMATERIAL structure
lpDirect3DMaterial->GetHandle(
lpD3DDevice, // Address of a DIRECT3DDEVICE object
lpD3DMat); // Address of a D3DMATERIAL structure
Material objects reside on the interface list and point both to the next material in a device's list and back to their associated device or devices. (For more information about this hierarchy, see Object Connectivity.) A material contains colors and may contain a texture handle. The material handle is used inside execute buffers or to set the background of a viewport. You can use the IDirect3DMaterial interface to get and set materials, retrieve handles, and reserve colors.