Game Development Reference
In-Depth Information
// draw the triangle to the left with flat shading
D3DXMatrixTranslation(&World, -1.25f, 0.0f, 0.0f);
Device->SetTransform(D3DTS_WORLD, &World);
Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
// draw the triangle to the right with gouraud shading
D3DXMatrixTranslation(&World, 1.25f, 0.0f, 0.0f);
Device->SetTransform(D3DTS_WORLD, &World);
Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}
4.5 Summary
Colors are described by specifying an intensity of red, green, and
blue. The additive mixing of these three colors at different intensi-
ties allows us to describe millions of colors. In Direct3D, we can
use the D3DCOLOR , the D3DCOLORVALUE ,orthe D3DXCOLOR type
to describe a color in code.
We sometimes treat a color as a 4D vector ( r , g , b , a ). Color vectors
are added, subtracted, and scaled just like regular vectors. On the
other hand, dot and cross products do not make sense for color vec-
tors, but component-wise multiplication does make sense for col-
ors. The symbol denotes component-wise multiplication, and it is
defined as: ( c 1 , c 2 , c 3 , c 4 ) ( k 1 , k 2 , k 3 , k 4 )=( c 1 k 1 , c 2 k 2 , c 3 k 3 , c 4 k 4 ).
We specify the color of each vertex, and then Direct3D uses the
current shade mode to determine how these vertex colors are used
to compute the pixel colors of the triangle during rasterization.
With flat shading, the pixels of a primitive are uniformly colored by
the color specified in the first vertex of the primitive. With Gouraud
shading, the colors at each vertex are interpolated linearly across
the face of the primitive.
Search WWH ::




Custom Search