Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Hooking OpenGL  (Read 5439 times)

0 Members and 1 Guest are viewing this topic.

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Hooking OpenGL
« on: July 09, 2012, 04:56:02 pm »
Hi Folks

Someone we work with needs to be able to "hook" our game so they can display overlaid graphics etc at any time. I know you can do this with DirectX but I don't know how with OpenGL.

So, given that they won't use SFML, how is best to achieve this? Any ideas?

Thanks
Ed
SFML 2.1

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Hooking OpenGL
« Reply #1 on: July 10, 2012, 09:56:45 am »
Hooks aren't very different from hacks, both in spelling and functionality. They are used in Windows in contexts where the developers of the application have no intention of letting an external library display graphics on their exclusively acquired screen at will. That's also why you need to resolve to ugly things like DLL injection which is one of the best features of Windows (sarcasm intended).

If you already know that this someone needs to display overlaid graphics during development you can create an API that lets them do this without the need for ugly hacks. That way you will also have an easier time porting your application to multiple platforms.

If it turns out they are stubborn and insist on doing it the DirectX way then I can only say that it will be one hell of a ride. OpenGL is quite different from DirectX and hooking into the drawing procedures of your application at the right time is going to be a lot of fun to try. OpenGL makes use of a state machine in its workings whereas DirectX does not. Wanting to draw the right things at the right time in the right state is going to cost a lot of time experimenting.

Just recommend the first method I described. If they opt for the second, the most you can do is give them the source code and wish them luck.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: Hooking OpenGL
« Reply #2 on: July 10, 2012, 10:14:12 am »
Hi

Thanks for the answer; though maybe I didn't explain well enough in my OP.

We can't offer an API for the other company to do their bit - their system really has full control over our game, and tells our game that something has happened and the game needs to be stopped, so they can overlay some graphics and wait for user input. During this time, our game just sends mouse events back to their system.

All they need to do is to add some OpenGL draw calls after we render, but before the screen is updated. I don't know how this is done in DirectX but it just works. They want to do the same for OpenGL.

Maybe its they who need to offer an API call, which we call every render time, to check if stuff needs drawing. But can they actually do this in another process? I don't know. I am not an OpenGL expert by any means!

Thanks
Ed

SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Hooking OpenGL
« Reply #3 on: July 10, 2012, 01:24:02 pm »
A few years ago, FRAPS had this document explaining how they managed to inject the FPS counter into the application's rendering (don't know where this document is now). If I remember correctly, they used a proxy OpenGL DLL that was redefining the SwapBuffers() function to first render their own stuff and then call the original SwapBuffer. Because SwapBuffer is called exactly once for each frame, and always at the end, it is the best entry point for additional stuff to be drawn.

Now I can't tell you more about how they implemented that. Did they use DLL injection? Did they just provide a dummy OpenGL DLL? I have no idea.

There is also gDEBugger, which is able to catch everything that is exchanged between your app and OpenGL. So it probably uses a similar technique.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Hooking OpenGL
« Reply #4 on: July 10, 2012, 05:37:24 pm »
We can't offer an API for the other company to do their bit - their system really has full control over our game, and tells our game that something has happened and the game needs to be stopped, so they can overlay some graphics and wait for user input. During this time, our game just sends mouse events back to their system.

All they need to do is to add some OpenGL draw calls after we render, but before the screen is updated. I don't know how this is done in DirectX but it just works. They want to do the same for OpenGL.

Maybe its they who need to offer an API call, which we call every render time, to check if stuff needs drawing. But can they actually do this in another process? I don't know. I am not an OpenGL expert by any means!
The easiest way would be to specify a functor that gets called at a certain given point in your draw code. It would be set by them at some point in time. Or if you know that their module will be present all the time you can hard code the call into your application. You would of course need to know the signature of the function in advance. This would also count as an API. That way they would also know when it is safe to issue their own calls because by calling their function you have already prepared yourself for whatever is to come. The same can be done for all input events as well.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).