Saturday, December 17, 2016

How does one write to another process's OpenGL/DirectX context?


I want to write a short of chat client that display the messages in-game (OpenGL/DirectX), but I really don't know how to handle this.


It is easy to write my client in my graphic context... but what about the other game-apps context?.


My primary target is Windows and Win 7, then mac, then Linux. But I would be happy to solve it for Windows.


By the way, it should try to be the most compatible with different DX versions and OGL versions.



Answer



One of the most common ways to render into another application's GL or D3D rendering context is to hook the creation of the context or device objects in that application's process. This will let you gain access to the returned context or device pointer. You can then hook the actual rendering invocation methods (for example, Present() in D3D) and inject your own rendering before or after the rendering of the hooked process.


Google can provide a wealth of links on hooking/detouring/patching GL or D3D DLLs to enable this. For example:



Because you are patching the rendering API DLLs (essentially), you will have to do this different for D3D and OpenGL -- there is no way to do it in a uniform fashion for both APIs. You will probably need to write different code for Mac and Windows machines as well, even when utilizing OpenGL.



D3D9 on Windows supports hardware overlay surfaces in some scenarios, which can be much easier to use (I believe this is what some voice chat clients like Ventrilo use) if they do what you want. I don't know if OpenGL provides something similar -- it would likely be through an extension.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...