====================================================================================
void render( void )
{
D3DXMATRIX matView;
D3DXMATRIX matWorld;
D3DXMATRIX matRotation;
D3DXMATRIX matTranslation;
//
// Render to the left viewport
//
D3DVIEWPORT9 leftViewPort;
leftViewPort.X = 0;
leftViewPort.Y = 0;
leftViewPort.Width = g_dwBackBufferWidth / 2;
leftViewPort.Height = g_dwBackBufferHeight;
leftViewPort.MinZ = 0.0f;
leftViewPort.MaxZ = 1.0f;
g_pd3dDevice->SetViewport( &leftViewPort );
// Now we can clear just view-port's portion of the buffer to red...
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE( 1.0f, 0.0f, 0.0f, 1.0f ), 1.0f, 0 );
g_pd3dDevice->BeginScene();
{
// For the left view-port, leave the view at the origin...
D3DXMatrixIdentity( &matView );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
// ... and use the world matrix to spin and translate the teapot
// out where we can see it...
D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f );
D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
matWorld = matRotation * matTranslation;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetMaterial( &g_teapotMtrl );
g_pTeapotMesh->DrawSubset(0);
}
g_pd3dDevice->EndScene();
//
// Render to the right viewport
//
D3DVIEWPORT9 rightViewPort;
rightViewPort.X = g_dwBackBufferWidth / 2;
rightViewPort.Y = 0;
rightViewPort.Width = g_dwBackBufferWidth / 2;
rightViewPort.Height = g_dwBackBufferHeight;
rightViewPort.MinZ = 0.0f;
rightViewPort.MaxZ = 1.0f;
g_pd3dDevice->SetViewport( &rightViewPort );
// Now we can clear just view-port's portion of the buffer to green...
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE( 0.0f, 1.0f, 0.0f, 1.0f ), 1.0f, 0 );
g_pd3dDevice->BeginScene();
{
// For the right view-port, translate and rotate the view around
// the teapot so we can see it...
D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f );
D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
matView = matRotation * matTranslation;
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
// ... and don't bother with the world matrix at all.
D3DXMatrixIdentity( &matWorld );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetMaterial( &g_teapotMtrl );
g_pTeapotMesh->DrawSubset(0);
}
g_pd3dDevice->EndScene();
//
// We're done! Now, we just call Present()
//
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}