Overlay/Get FPS of window

3

4

I'm not sure if this is more proper in stackexchange, but how do programs such as steam (the game overlay) and FRAPS overlay data over a window? I've noticed that the overlay/fraps can only work on windows that are driven by opengl/directx, or is the overlay just a feature int he windows api? Also, how does fraps get the fps of the window?

agz

Posted 2013-01-25T05:01:17.347

Reputation: 6 820

Answers

6

FRAPS and similar programs work by hooking the API calls used to display the rendered frame (for example IDirect3DDevice9::Present method or OpenGL SwapBuffers() )

Essentially when a game is about to display a new frame, the program execution is transferred to the hook installed by FRAPS. That code can modify the frame any way it wants, drawing the FPS counter over it, changing colors or taking a screenshot for video recording. When that’s finished FRAPS calls the original API to display the frame.

Different graphics APIs need different hooks, so FRAPS must have separate implementations for OpenGL and Direct3D 8 / 9 / 10 etc. It also means when new technologies (like Direct2D) are released FRAPS needs updates to handle these.

The actual process of installing and removing hooks is rather convoluted; you can find more information in this StackOverflow question:

Hooking DirectX EndScene from an injected DLL

or here: Case study: Fraps

Counting FPS is simple; programs just need the time elapsed between frames. For example: frame time = 20 ms; FPS = 1000 ms / 20 ms = 50;

If frame times vary a lot, the FPS value will wildly fluctuate. A better method would be calculating an average of the last 10 frames or counting the number of frames drawn over the last second. Although numbers in FRAPS seem to change too fast.

Ryck

Posted 2013-01-25T05:01:17.347

Reputation: 606

Would this also be how steam overlay works? – agz – 2013-01-25T18:51:50.197

Yes, generally every software which displays an overlay on fullscreen OpenGL or D3D applications works the same way – Ryck – 2013-01-25T19:52:28.340