It depends on the game you are injecting into, since the way you are going to draw onto the screen matters on the rendering engine the game is using.
Fraps has several hooks internally that will attach to the proper functions based on what the game is currently using. Which includes:
- Direct3D8
- Direct3D9
- Direct3D10/11
- OpenGL
And so on, (they don't have a full list of what engines are supported but yea..)
Taking Direct3D8/9 as an example, you'd need to hook at least 'EndScene' in order to do your calculations and drawing. Also keep in mind if you only hook EndScene any textures and objects you create must be marked as 'D3DPOOL_MANAGED' or you will have to hook 'Reset' as well and handle recreating your objects when the device is lost.
So once you have your hooks, you'll need to create a text object to draw with, and some counter code to handle the FPS calculations.
The calculation is fairly simple, since EndScene can be called multiple times per-scene, per-second you need to monitor for the time difference and not depend only on the call count to the function.
Code:
int m_FPS;
int m_Count;
unsigned long m_StartTime;
HRESULT __stdcall MyEndSceneHook( )
{
m_Count++;
if (timeGetTime() >= (m_StartTime + 1000))
{
m_FPS = m_Count;
m_Count = 0;
m_StartTime = timeGetTime();
}
// Draw the fps here..
return m_OriginalDevice->EndScene();
}
You can also use the query performance API if you want a high resolution timer with more accuracy.