DXUT 添加对话框背景
第一步
在DXUTgui.cpp中添加
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;
第二步
在DXUTgui.cpp中修改CDXUTDialog::OnRender9( floatfElapsedTime )函数
找到pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );把它注释掉或删掉
将 if(!m_bMinimized && bBackgroundIsVisible )
{
内容替换为
DXUT_SCREEN_VERTEX_TEXTURE vertices[] =
{
{ ( float )m_x, ( float )m_y, 0,1, m_colorTopLeft, 0, 0},
{ ( float )m_x+m_width, ( float )m_y, 0,1, m_colorTopRight, 1, 0},
{ ( float )m_x+m_width, ( float )m_y+m_height, 0,1,m_colorBottomRight, 1, 1},
{ ( float )m_x, ( float )m_y, 0, 1,m_colorTopLeft, 0, 0},
{ ( float )m_x+ ( float)m_width, ( float )m_y+ ( float )m_height, 0,1, m_colorBottomRight, 1, 1},
{ ( float )m_x, ( float )m_y+ ( float )m_height, 0,1,m_colorBottomLeft, 0, 1}
};
pd3dDevice->SetVertexShader( NULL );
pd3dDevice->SetPixelShader( NULL );
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->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 4, vertices, sizeof(DXUT_SCREEN_VERTEX_TEXTURE ) );
}
第三步
在DXUTgui.h中找到CDXUTDialog类的声明
添加成员变量
int m_iTexture; 并在构造函数中初始化为-1
添加成员函数声明
void SetBackgroundTextures(const wchar_t*wch);
在DXUTgui.cpp中添加函数实现
voidCDXUTDialog::SetBackgroundTextures(const wchar_t* wch)
{
m_iTexture = m_pManager-> AddTexture(wch);
}
第四步
在SimpleSample.cpp的OnD3D9ResetDevice()中添加
g_HUD.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206 ),
D3DCOLOR_ARGB( 255, 255, 255, 255 ),
D3DCOLOR_ARGB( 255, 255, 255, 255 ),
D3DCOLOR_ARGB( 255, 255, 255, 255 ) );//材质背景颜色
g_HUD.SetSize( 170, 170 );
g_HUD.SetBackgroundTextures(L"bcgr1.jpg");添加对话框背景图片
当对话框填充窗口时, 就是为窗口背景