#pragma region Setup the render target texture description
D3D11_TEXTURE2D_DESC textureDesc;
textureDesc.Width = 256;
textureDesc.Height = 256;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
V_RETURN( pd3dDevice->CreateTexture2D( &textureDesc, NULL, &g_pRenderTargetTexture ) );
#pragma endregion
#pragma region Setup the description of the render target view
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;
V_RETURN( pd3dDevice->CreateRenderTargetView( g_pRenderTargetTexture, &renderTargetViewDesc, &g_pRenderTargetView) );
#pragma endregion
However, if I get the current render target view, which is got with a function named DXUTGetD3D11RenderTargetView, then just render. But the same code, saving to a texture, it does not work, everything is black
ID3D11Resource *backbufferRes;
pRTV->GetResource(&backbufferRes);
D3D11_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = 0;
texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
texDesc.Width = 640; // the current viewport is 640x480
texDesc.Height = 480;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D11_USAGE_DEFAULT;
ID3D11Texture2D *texture;
V( pd3dDevice->CreateTexture2D(&texDesc, 0, &texture) );
pd3dImmediateContext->CopyResource(texture, backbufferRes);
hr = D3DX11SaveTextureToFile( pd3dImmediateContext, texture, D3DX11_IFF_JPG, L"test.jpg");
SAFE_RELEASE( texture );
SAFE_RELEASE( backbufferRes );
I do not understand the reason, anybody have experienced this problem, help me please. Thank in advance.