DXUT 添加图片

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 ) );

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值