Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take screenshot of DirectX full-screen application

This boggles me. DirectX bypasses everything and talks directly to the device driver, thus GDI and other usual methods won't work - unless Aero is disabled (or unavailable), all that appears is a black rectangle at the top left of the screen. I have tried what other have suggested on several forums, using DirectX to get the back buffer and save it, but I get the same result:

device->GetFrontBufferData(0, surface); D3DXSaveSurfaceToFile("fileName", D3DXIFF_BMP, surface, NULL, NULL);

Is there any way to get a screenshot of another full-screen DirectX application when Aero is enabled?

like image 554
CMircea Avatar asked Dec 25 '09 22:12

CMircea


2 Answers

Here is a C# example of hooking IDirect3DDevice9 objects via DLL injection and function hooking using EasyHook (like Microsoft Detours). This is similar to how FRAPS works.

This allows you to capture the screen in windowed / fullscreen mode and uses the back buffer which is much faster than trying to retrieve data from the front buffer.

A small C++ helper DLL is used to determine the methods of the IDirect3DDevice9 object to hook at runtime.

Update: for DirectX 10/11 see Screen capture and overlays for D3D 9, 10 and 11

like image 22
Justin Stenning Avatar answered Sep 17 '22 12:09

Justin Stenning


Have a look at Detours.

Using Detours, you can instrument calls like Direct3DCreate9, IDirect3D9::CreateDevice and IDirect3D9::Present in which you perform the operations necessary to setup and then do a frame capture.

like image 186
Gregory Pakosz Avatar answered Sep 19 '22 12:09

Gregory Pakosz