struct DXUT_SCREEN_VERTEX_TEXTURE
{
float x, y, z, r;
unsigned long color;
float tu, tv;
static DWORD FVF;
};
DWORD DXUT_SCREEN_VERTEX_TEXTURE::FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;
class CTexture
{
public:
CTexture();
void Init(CDXUTDialogResourceManager* pManager);
void SetTexture(const wchar_t* wch, int top_left, int top_right, int bottom_left, int bottom_right);
void SetBackgroundColors( D3DCOLOR colorTopLeft, D3DCOLOR colorTopRight, D3DCOLOR colorBottomLeft, D3DCOLOR colorBottomRight );//背景渐变
void Render();
CDXUTDialogResourceManager* m_pManager;
int m_bcgrx;
int m_bcgry;
int m_bcgrw;
int m_bcgrh;
D3DCOLOR m_colorTopLeft;
D3DCOLOR m_colorTopRight ;
D3DCOLOR m_colorBottomLeft ;
D3DCOLOR m_colorBottomRight;
int m_iTexture;
};
CTexture::CTexture()
{
m_bcgrx = 0;
m_bcgry = 0;
m_bcgrw = 0;
m_bcgrh = 0;
m_colorTopLeft = D3DCOLOR_ARGB( 255, 255, 255, 255 );
m_colorTopRight = D3DCOLOR_ARGB( 255, 255, 255, 255 );
m_colorBottomLeft = D3DCOLOR_ARGB( 255, 255, 255, 255 );
m_colorBottomRight =D3DCOLOR_ARGB( 255, 255, 255, 255 );
m_iTexture = -1;
}
void CTexture:: Init(CDXUTDialogResourceManager* pManager)
{
m_pManager = pManager;
}
void CTexture::SetTexture(const wchar_t * wch, int bcgrx, int bcgry, int bcgrw, int bcgrh)
{
m_iTexture = m_pManager-> AddTexture(wch);
m_bcgrx = bcgrx;
m_bcgry = bcgry;
m_bcgrw = bcgrw;
m_bcgrh = bcgrh;
m_iTexture;
}
void CTexture::SetBackgroundColors( D3DCOLOR colorTopLeft, D3DCOLOR colorTopRight, D3DCOLOR colorBottomLeft,
D3DCOLOR colorBottomRight )
{
m_colorTopLeft = colorTopLeft;
m_colorTopRight = colorTopRight;
m_colorBottomLeft = colorBottomLeft;
m_colorBottomRight = colorBottomRight;
}
void CTexture::Render()
{
IDirect3DDevice9* pd3dDevice = m_pManager->GetD3D9Device();
DXUT_SCREEN_VERTEX_TEXTURE vertices[] =
{
{ ( float )m_bcgrx, ( float )m_bcgry, 0,1, m_colorTopLeft, 0, 0},
{ ( float )m_bcgrx+m_bcgrw, ( float )m_bcgry, 0,1, m_colorTopRight, 1, 0},
{ ( float )m_bcgrx+m_bcgrw, ( float )m_bcgry+m_bcgrh, 0, 1,m_colorBottomRight, 1, 1},
{ ( float )m_bcgrx, ( float )m_bcgry, 0, 1,m_colorTopLeft, 0, 0},
{ ( float )m_bcgrx+ ( float )m_bcgrw, ( float )m_bcgry+ ( float )m_bcgrh, 0,1, m_colorBottomRight, 1, 1},
{ ( float )m_bcgrx, ( float )m_bcgry+ ( float )m_bcgrh, 0,1, m_colorBottomLeft, 0, 1}
};
pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
if(m_iTexture !=-1)
pd3dDevice->SetTexture( 0, m_pManager->GetTextureNode(m_iTexture)->pTexture9 );
pd3dDevice->SetFVF( DXUT_SCREEN_VERTEX_TEXTURE::FVF );
pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 4, vertices, sizeof( DXUT_SCREEN_VERTEX_TEXTURE ) );
}