Microsoft DirectX 8.0 (C++) |
A material defines the color that is reflected off the surface of a geometric object when a light hits it. The following code fragment uses the D3DMATERIAL8 structure to create a material that is yellow.
D3DMATERIAL8 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL8) ); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl );
The diffuse color and ambient color for the material are set to yellow. The call to the IDirect3DDevice8::SetMaterial method applies the material to the Microsoft® Direct3D® device used to render the scene. The only parameter that SetMaterial accepts is the address of the material to set. After this call is made, every primitive will be rendered with this material until another call is made to SetMaterial that specifies a different material.
Now that material has been applied to the scene, the next step is to create a light. This is described in Step 2.2: Creating a Light.