Selecting a Material for Rendering

After you've created a material object, set its properties, and retrieved its handle, you're ready to render. You select the material into a Direct3D device by calling the device's IDirect3DDevice3::SetLightState method with the appropriate flags. The SetLightState method is a multi-purpose method; when calling the method to select the rendering material, set the first parameter to D3DLIGHTSTATE_MATERIAL, and set the second parameter to the handle of the material you want to use. The following code shows what this call commonly looks like

    //
    // For this example, hMat is a variable of type D3DMATERIALHANDLE that has 
    // been set to a valid material handle.  The lpDev3 variable is a pointer 
    // to the IDirect3DDevice3 interface of the device that will use the material.
    //
    HRESULT hr; 
 
    // Set the current material. 
    hr = lpDev3->SetLightState(D3DLIGHTSTATE_MATERIAL, hMat); 
    if(FAILED(hr)) 
    { 
        REPORTERR(hr); 
        return hr; 
    } 
 

Note  A Direct3D device can render with only one material at a time. After setting the current material, Direct3D will use that material for all polygons until another material is selected. You can change the currently used material at any time.