반응형
bool CopyTexture(LPDIRECT3DDEVICE9 pDevice, LPDIRECT3DTEXTURE9 pDestTex, RECT* pDestRect, LPDIRECT3DTEXTURE9 pSrcTex, RECT* pSrcRect) { if (!pDevice || !pDestTex || !pSrcTex) return false; // Get Surface LPDIRECT3DSURFACE9 pSrcSurf, pDestSurf; if (FAILED(pSrcTex->GetSurfaceLevel(0, &pSrcSurf))) return false; if (FAILED(pDestTex->GetSurfaceLevel(0, &pDestSurf))) return false; pSrcTex->Release(); pDestTex->Release(); D3DSURFACE_DESC desc; pDestTex->GetLevelDesc(0, &desc); LPD3DXRENDERTOSURFACE pRenderToSurface = NULL; HRESULT hrSurf = D3DXCreateRenderToSurface(pDevice, desc.Width, desc.Height, desc.Format, FALSE, D3DFMT_UNKNOWN, &pRenderToSurface); // Calc Size int nSrcWidth = pSrcRect->right - pSrcRect->left; int nSrcHeight = pSrcRect->bottom - pSrcRect->top; int nDestWidth = pDestRect->right - pDestRect->left; int nDestHeight = pDestRect->bottom - pDestRect->top; // Draw D3DVIEWPORT9 vp = {0, 0, desc.Width, desc.Height, 0, 1.0f}; HRESULT hrBegin = pRenderToSurface->BeginScene(pDestSurf, &vp); if (SUCCEEDED(hrBegin)) { pDevice->Clear(0L, NULL, D3DCLEAR_TARGET, 0xFF000000, 1.0f, 0L); pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); TVERTEX_RHWPT1 vertex[4]; vertex[0].fU1 = 0; vertex[0].fV1 = 0; vertex[1].fU1 = 0; vertex[1].fV1 = 1; vertex[2].fU1 = 1; vertex[2].fV1 = 0; vertex[3].fU1 = 1; vertex[3].fV1 = 1; // Copy Dest vertex[0].vPos = D3DXVECTOR4(-0.5f, -0.5f, 0.5f, 1.0f); vertex[1].vPos = D3DXVECTOR4(-0.5f, desc.Height - 0.5f, 0.5f, 1.0f); vertex[2].vPos = D3DXVECTOR4(desc.Width - 0.5f, -0.5f, 0.5f, 1.0f); vertex[3].vPos = D3DXVECTOR4(desc.Width - 0.5f, desc.Height - 0.5f, 0.5f, 1.0f); pDevice->SetTexture(0, pDestTex); pDevice->SetFVF(TVERTEX_RHWPT1::FVF); pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertex, sizeof(TVERTEX_RHWPT1)); // Copy Source vertex[0].vPos = D3DXVECTOR4(pDestRect->left - 0.5f, pDestRect->top - 0.5f, 0.5f, 1.0f); vertex[1].vPos = D3DXVECTOR4(pDestRect->left - 0.5f, pDestRect->top + nDestHeight - 0.5f, 0.5f, 1.0f); vertex[2].vPos = D3DXVECTOR4(pDestRect->left + nDestWidth - 0.5f, pDestRect->top - 0.5f, 0.5f, 1.0f); vertex[3].vPos = D3DXVECTOR4(pDestRect->left + nDestWidth - 0.5f, pDestRect->top + nDestHeight - 0.5f, 0.5f, 1.0f); pDevice->SetTexture(0, pSrcTex); pDevice->SetFVF(TVERTEX_RHWPT1::FVF); pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertex, sizeof(TVERTEX_RHWPT1)); HRESULT hrEnd = pRenderToSurface->EndScene(D3DX_FILTER_LINEAR); } pRenderToSurface->Release(); return true; }
반응형
'Game Dev > Article' 카테고리의 다른 글
Internet File Download (0) | 2009.02.20 |
---|---|
배열과 Loop를 다루는 3가지 방법 (0) | 2009.01.12 |
소프트웨어 일정 예측 (1) | 2008.10.22 |
Open Partner File (0) | 2008.09.24 |