View Full Version : Obtaining backbuffer of entire monitor

07-09-2014, 07:36 AM
For my application, I need to copy the window of a 3rd party application into a texture. I don't have access to the OpenGL context of this 3rd party application, so my hope is that I can access the backbuffer of the entire monitor. The Windows API has a Direct3D method (http://msdn.microsoft.com/en-us/library/windows/desktop/bb174379(v=vs.85).aspx) to do this. I'm using Windows 7, but my application is in OpenGL. Is there any way to do this with OpenGL? Or perhaps use the Direct3D method and copy the D3D surface to an OpenGL texture?

07-09-2014, 11:07 AM
this is a generic question
1) you need to do screen capture of an application running in a separate process? => you need screen capture API and that is independent of what type of rendering the window is doing (D3D or GL)

2) the window is in same process of your application, even better same thread (so the window is controlled by some kind of API) => you need to add in someway a callback function when the window is performing any rendering (and has an active openGL context). If the API of the window expose callbacks functions chances are good you will succed in a simple way by simply querying content of backbuffer (i think you just need to bind FBO with id = 0 and read it like in any regular application). The best place to do it is after rendering is finished (because it's harder you can messup GL states, if that is not the case, you have to query states and restore them after you did your work)

2.b) if the window has crappy API then you can hack it (I don't suggest to do it, I don't know how to do it, It may be legal or not). Just use a code injector and replace the call to "SwapBuffers" with your function that do

-Set your states
-ReadContent and send to your code (maybe you have a global preallocated buffer that you can easily access)
-Restore your states
-SwapBuffers (to preserve functionality)

07-09-2014, 11:34 AM
Yeah, the application is a separate process and it does not provide me with an API. The D3D::GetBackBuffer method in the Windows API allows you to copy the backbuffer for the entire desktop into a D3D surface, so I thought I could do something like that. Perhaps there is a way to do it in OpenGL, or a way to do it in D3D and convert the surface to an OpenGL texture.