Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Would this also be how steam overlay works? –  agz Jan 25 '13 at 18:51
    
Yes, generally every software which displays an overlay on fullscreen OpenGL or D3D applications works the same way –  Ryck Jan 25 '13 at 19:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.