Game Development Reference
In-Depth Information
{
//
// Update
//
// increase/decrease alpha via keyboard input
if( ::GetAsyncKeyState('A') & 0x8000f )
TeapotMtrl.Diffuse.a += 0.01f;
if( ::GetAsyncKeyState('S') & 0x8000f )
TeapotMtrl.Diffuse.a -= 0.01f;
// force alpha to [0, 1] interval
if(TeapotMtrl.Diffuse.a > 1.0f)
TeapotMtrl.Diffuse.a = 1.0f;
if(TeapotMtrl.Diffuse.a < 0.0f)
TeapotMtrl.Diffuse.a = 0.0f;
//
// Render
//
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
0xffffffff, 1.0f, 0);
Device->BeginScene();
// Draw the background
D3DXMATRIX W;
D3DXMatrixIdentity(&W);
Device->SetTransform(D3DTS_WORLD, &W);
Device->SetFVF(Vertex::FVF);
Device->SetStreamSource(0, BkGndQuad, 0, sizeof(Vertex));
Device->SetMaterial(&BkGndMtrl);
Device->SetTexture(0, BkGndTex);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
// Draw the teapot
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
D3DXMatrixScaling(&W, 1.5f, 1.5f, 1.5f);
Device->SetTransform(D3DTS_WORLD, &W);
Device->SetMaterial(&TeapotMtrl);
Device->SetTexture(0, 0);
Teapot->DrawSubset(0);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}
Search WWH ::




Custom Search