This is actually a follow up to this question How to capture the screen in DirectX 9 to a raw bitmap in memory without using D3DXSaveSurfaceToFile

The proponent of the best solution suggested that I should look at a shader program to capture the screen. How could I do that. I have no clue on how can I use a shader program to do that.


Shaders don't capture the screen in and of themselves. What's being suggested in the "shader based approach" is to:

1) Use render-to-texture or the like to render your entire scene to a single texture 2) Render that texture (with, say, a fullscreen quad) to your final output (or another texture if you want to chain effects or do multi-pass effects) using pixel and/or vertex shaders written in HLSL to apply your filtering effect instead of C++.

This has the advantage of keeping everything in GPU memory instead of spending your limited memory bandwidth copying everything from GPU to system memory (where C++ can work on it) and back (where it can be rendered.)

Methods of note for wrangling pixel shaders (commonly used for operations such as bluring, depth of field effects, tinting, you name it): D3DXCompileShaderFromFile, CreatePixelShader, SetPixelShader, SetPixelShaderConstantF

And for render targets: SetRenderTarget, BeginScene, and EndScene.

  • \$\begingroup\$ wonderful. That makes sense. I was quite confused. \$\endgroup\$ – cloudraven Nov 28 '12 at 8:24

You cannot directly use a shader program to get the screen but you can copy the back buffer from the gpu to the cpu and then do what you want with it, be it save, etc.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.