|
发表于 2005-11-25 11:56:00
|
显示全部楼层
Re:怎样在D3D下高效地绘制矩形?
//--------------------------------------------------------------------------------------
HRESULT CDXUTDialog: rawRect( RECT* pRect, D3DCOLOR color )
{
RECT rcScreen = *pRect;
OffsetRect( &rcScreen, m_x, m_y );
// If caption is enabled, offset the Y position by its height.
if( m_bCaption )
OffsetRect( &rcScreen, 0, m_nCaptionHeight );
DXUT_SCREEN_VERTEX vertices[4] =
{
(float) rcScreen.left -0.5f, (float) rcScreen.top -0.5f, 0.5f, 1.0f, color, 0, 0,
(float) rcScreen.right -0.5f, (float) rcScreen.top -0.5f, 0.5f, 1.0f, color, 0, 0,
(float) rcScreen.right -0.5f, (float) rcScreen.bottom -0.5f, 0.5f, 1.0f, color, 0, 0,
(float) rcScreen.left -0.5f, (float) rcScreen.bottom -0.5f, 0.5f, 1.0f, color, 0, 0,
};
IDirect3DDevice9* pd3dDevice = m_pManager->GetD3DDevice();
// Since we're doing our own drawing here we need to flush the sprites
m_pManager->m_pSprite->Flush();
IDirect3DVertexDeclaration9 *pDecl = NULL;
pd3dDevice->GetVertexDeclaration( &pDecl ); // Preserve the sprite's current vertex decl
pd3dDevice->SetFVF( DXUT_SCREEN_VERTEX::FVF );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, vertices, sizeof(DXUT_SCREEN_VERTEX) );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
// Restore the vertex decl
pd3dDevice->SetVertexDeclaration( pDecl );
pDecl->Release();
return S_OK;
}
|
|