title: How to save backbuffer to file in DirectX 10?
body: <p>I want to render a video frame-by-frame using DirectX 10. The frames would be processed later by some other tool like mencoder or ffmpeg.</p>
  
  <p>I had no problems doing so in DX9 using <code>D3DXSaveSurfaceToFile</code>.</p>
  
  <p>Now, in DX10 I've found <code>D3DX10SaveTextureToFile</code>, but had no luck using it to save my backbuffer.</p>
  
  <p>I use the following code:</p>
  
  <pre><code>ID3D10Resource *backbufferRes;
  _defaultRenderTargetView-&gt;GetResource(&amp;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-&gt;CreateTexture2D(&amp;texDesc, 0, &amp;texture) );
  _device-&gt;CopyResource(texture, backbufferRes);
  
  V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_DDS, filename) );
  texture-&gt;Release();
  </code></pre>
  
  <p>This creates a .dds image that can not be opened by any sort of DDS view/editor I know of.</p>
  
  <p>What's wrong with my code?</p>