Copy a ID3D10Texture2D surface to a HBitmap
-
Monday, September 28, 2009 8:53 AM
Hey, guys:
I want to draw some items on a trasparent window with d3d10, first I create a Layed window and hope to use UpdateLayedWindow to refresh items, then create a HBitmap hope to copy the surface of a d3d10 rendertargetview, and then bind HBitmap to a CompatableDC, so it can be painted when UpdateLayedWindow is called.
When it finished drawing with direct3d, I can get a ID3D10Texture2D object which is queryed by ID3D10RenderTargetView, after Map it I can copy its contents to HBitmap. But I find that the result is not what I wanted(with some unexpected lines).
Why there are some unexpected lines, Anyone can tell me?
code in function Render():
{
D3DXVECTOR4 clearColor(0.0f, 0.0f, 1.0f, 0.7f);
m_pd3dDevice->ClearRenderTargetView(m_pRenderTargetView, (float*)clearColor);
// rendering items
// ...
// end
ID3D10Texture2D* pSrcResource = NULL;
m_pRenderTargetView->GetResource(reinterpret_cast<ID3D10Resource**>(&pSrcResource));
if ( m_pDstResource )
{
m_pd3dDevice->CopyResource(m_pDstResource, pSrcResource);
D3D10_MAPPED_TEXTURE2D Data;
hr = m_pDstResource->Map(0, D3D10_MAP_READ, 0, &Data);
if ( SUCCEEDED(hr) )
{
memcpy(m_pBits, Data.pData, 4 * m_size.cx * m_size.cy);
m_pDstResource->Unmap(0);
}
}
pSrcResource->Release();
m_pSwapChain10->Present(0, 0);
POINT ptWinPos = { m_rc.left, m_rc.top};
POINT ptSrc = { 0, 0};
SIZE szWin = { m_size.cx, m_size.cy };
BLENDFUNCTION stBlend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
UpdateLayeredWindow(m_hWnd,GetWindowDC(m_hWnd),&ptWinPos,&szWin,m_hDC,&ptSrc,0,&stBlend,ULW_ALPHA);
}