Jump to content
  • Advertisement
Sign in to follow this  

Saving the backbuffer directly in DX10

This topic is 2783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all!

I'm trying to add a sort of screenshot feature to my DX10 app, and it starts to give me a serious headache.

This is my screenshot method:
void Whatever::SaveScreen(const WCHAR* filename)
// backbufferSurfDesc is saved at OnResizedSwapChain call
ID3D10Resource *backbufferRes;

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;
V( _device->CreateTexture2D(&texDesc, 0, &texture) );
_device->CopyResource(texture, backbufferRes);

V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_PNG, filename) );

Now, obviously I'm doing something the wrong way, because D3DX10SaveTextureToFile fails with E_FAIL (guess E stands for EPIC [wink]).

Is it possible to use D3DX10SaveTextureToFile without a render-to-texture before it?


Share this post

Link to post
Share on other sites
Its possible that it wont save because PNG can only store certain pixel formats. Try using D3DX10_IFF_DDS and see if it saves successfully.

It could also be that filename is invalid and/or you dont have write permission in the directory where you are attempting to save it.

If all else fails you could try saving the back buffer directly without copying it to a staging first?

Share this post

Link to post
Share on other sites
Changing the file format to D3DX10_IFF_DDS indeed solved the error part, but I get a corrupted DDS.
I have tried to open it with the DX Texture Tool, with nVidia's texture viewer and even with Gimp's DDS plug-in. All in vain.
I have uploaded the files here, if anyone feels like giving it a try.

BTW, using backbufferRes directly in D3DX10SaveTextureToFile "work" just the same. No error, corrupted DDS.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!