title: c++ Directx11 capture screen and save to file
body: <p>i've got problem with saving texture2d to file, it always gives me black image.
  Here is code:</p>
  
  <pre><code>HRESULT hr = SwapChain-&gt;GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast&lt; void** &gt;( &amp;g_pSurface ) );
  if( g_pSurface )
  {
      ID3D11Texture2D* pNewTexture = NULL;
  
      D3D11_TEXTURE2D_DESC description;
      g_pSurface-&gt;GetDesc( &amp;description );
      description.BindFlags = 0;
      description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
      description.Usage = D3D11_USAGE_STAGING;
  
      HRESULT hr = d3d11Device-&gt;CreateTexture2D( &amp;description, NULL, &amp;pNewTexture );
      if( pNewTexture )
      {
          d3d11DevCon-&gt;CopyResource( pNewTexture, g_pSurface );
  
          hr=D3DX11SaveTextureToFileA(d3d11DevCon, pNewTexture, D3DX11_IFF_BMP, "screen.bmp");
          return;
      }
  }
  </code></pre>
  
  <p>What am i doing wrong?</p>