Hi people,
I'm wondering on how to show my FPS on the top right of my window...
Can anyone tell me how to do this?
Hi people,
I'm wondering on how to show my FPS on the top right of my window...
Can anyone tell me how to do this?
It consists of two parts.
1) Calculating the FPS.
2) Displaying a bit of text.
Which of the two do you need help with?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Calculating the FPS:
Code:DWORD TimeStart; DWORD TimeFinish; DWORD FPS; TimeStart = GetTickCount(); // render code goes here TimeFinish = GetTickCount(); FPS = 1000 / (TimeFinish-TimeStart);
Here is how I do it.
My setup is a bit complex because this particular example is setup for cubic environment mapping and post-processing effects using PS and VS 3.0. Needless to say the timeDelta gets passed to CalcFPS() which does the frame calculation.Code:int CD3DApp::EnterMsgLoop(void) { MSG msg; ::ZeroMemory(&msg, sizeof(MSG)); static float lastTime = (float)timeGetTime(); while(msg.message != WM_QUIT) { if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } else { float currTime = (float)timeGetTime(); float timeDelta = (currTime - lastTime)*0.001f; ScreenRender(timeDelta); lastTime = currTime; } } return msg.wParam; } void CD3DApp::CalcFPS(float timeDelta) { FrameCount++; TimeElapsed+=timeDelta; if (TimeElapsed>=1.0f) { FPS=(float)FrameCount/TimeElapsed; TimeElapsed=0.0f; FrameCount=0; } }
There are probably easier ways to do it, but for something as simple as a few characters for the FPS I would just overlay some appropriate bitmaps onto your primary frame before blitting it to the screen.