I would like to capture the contents of my front or rear buffer using DirectX 11 into an array of bytes, which I can then use as a texture or as a source to create a file. I have a swap chain, a lot of rendering results and the following code so far - which I will definitely call after the Present call.
ID3D11Texture2D* pSurface; HRESULT hr = m_swapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast< void** >( &pSurface ) ); if( pSurface ) { const int width = static_cast<int>(m_window->Bounds.Width * m_dpi / 96.0f); const int height = static_cast<int>(m_window->Bounds.Height * m_dpi / 96.0f); unsigned int size = width * height; if( m_captureData ) { freeFramebufferData( m_captureData ); } m_captureData = new unsigned char[ width * height * 4 ]; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC description = { width, height, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, { 1, 0 },
He always gives me black with zero alpha.
I usually have the option of interacting with GDI to use BitBlt to copy a bitmap from the swap chain, but I have limitations, which means that this is not an acceptable solution.
Nor can there be a D3DX library that contains the functionality to execute bits of this.
c ++ directx graphics directx-11
jheriko
source share