Game Development Reference
In-Depth Information
bool Setup()
{
// create vertex buffer
Device->CreateVertexBuffer(
3 * sizeof(ColorVertex),
D3DUSAGE_WRITEONLY,
ColorVertex::FVF,
D3DPOOL_MANAGED,
&Triangle,
0);
// fill the buffers with the triangle data
ColorVertex* v;
Triangle->Lock(0, 0, (void**)&v, 0);
v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255,
0,
0));
v[1] = ColorVertex( 0.0f, 1.0f, 2.0f, D3DCOLOR_XRGB( 0, 255,
0));
v[2] = ColorVertex( 1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB( 0,
0,
255));
Triangle->Unlock();
// set projection matrix
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)Width / (float)Height,
1.0f,
1000.0f);
Device->SetTransform(D3DTS_PROJECTION, &proj);
// set the render states
Device->SetRenderState(D3DRS_LIGHTING, false);
return true;
}
Then, the Display function draws Triangle twice in two different
positions and with different shade modes. The position of each triangle
is controlled with the world matrix— World .
bool Display(float timeDelta)
{
if( Device )
{
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
0xffffffff, 1.0f, 0);
Device->BeginScene();
Device->SetFVF(ColorVertex::FVF);
Device->SetStreamSource(0, Triangle, 0, sizeof(ColorVertex));
Search WWH ::




Custom Search