Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualkauna

Posted 10 October 2012 - 12:16 PM

Here is a code to save back buffer to a texture. I guess you can take the usable parts to save any texture to a file.

ID3D10Resource *backbufferRes;
_defaultRenderTargetView->GetResource(&backbufferRes);
D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
texDesc.Format = backbufferSurfDesc.Format;
texDesc.Height = backbufferSurfDesc.Height;
texDesc.Width = backbufferSurfDesc.Width;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc = backbufferSurfDesc.SampleDesc;
texDesc.Usage = D3D10_USAGE_STAGING;
ID3D10Texture2D *texture;
HRESULT hr;
V( _device->CreateTexture2D(&texDesc, 0, &texture) );
_device->CopyResource(texture, backbufferRes);
V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_DDS, filename) );
texture->Release();

Otherwise, have you checked your debug output? have you run the program with PIX?

Typical errors with render targets are such as :

- forgetting to unbind them as textures / rendertargets before using them else where for texture/render target.
- Invalid viewport settings.
- Invalid depth/stencil target with the render target (since D3D10 they must exactly have the same dimensions)

Cheers!

#1kauna

Posted 10 October 2012 - 12:15 PM

Here is a code to save back buffer to a texture. I guess you can take the usable parts to save any texture to a file.

ID3D10Resource *backbufferRes;
_defaultRenderTargetView->GetResource(&backbufferRes);
D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
texDesc.Format = backbufferSurfDesc.Format;
texDesc.Height = backbufferSurfDesc.Height;
texDesc.Width = backbufferSurfDesc.Width;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc = backbufferSurfDesc.SampleDesc;
texDesc.Usage = D3D10_USAGE_STAGING;
ID3D10Texture2D *texture;
HRESULT hr;
V( _device->CreateTexture2D(&texDesc, 0, &texture) );
_device->CopyResource(texture, backbufferRes);
V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_DDS, filename) );
texture->Release();

Otherwise, have you checked your debug output? have you run the program with PIX?

Typical errors with render targets are such as :

- forgetting to unbind them as textures / rendertargets before using them else where for texture/render target.
- Invalid viewport settings.

Cheers!

PARTNERS