GetTickCount function (Windows)
Syntax
C++
DWORD WINAPI GetTickCount(void); // Returns a DWORD, not float.
I want to calculate the FPS in the game and put in my dirextX menu.
How to do it? Interested in source code.
Here's what I found on the Internet at:
But it does not work.Code:DWORD FrameCnt; float TimeElapsed; float FPS; float oldTime; float newTime; float deltatime; FrameCnt++; newTime = GetTickCount(); deltatime = newTime - oldTime; TimeElapsed += deltatime; if(TimeElapsed >= 500.0) { FPS = 1000*(float)FrameCnt / TimeElapsed; TimeElapsed = 0.0f; FrameCnt = 0; }
GetTickCount function (Windows)
Syntax
C++
DWORD WINAPI GetTickCount(void); // Returns a DWORD, not float.
'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
--
VDV777 (05-03-2013)
char* GetFPS(void)
{
static int FPScounter = 0;
static float FPSfLastTickCount = 0.0f;
static float FPSfCurrentTickCount;
static char cfps[6] = "";
FPSfCurrentTickCount = clock() * 0.001f;
FPScounter++;
if((FPSfCurrentTickCount - FPSfLastTickCount) > 1.0f)
{
FPSfLastTickCount = FPSfCurrentTickCount;
sprintf(cfps," %d",FPScounter);
FPScounter = 0;
}
return cfps;
}
Using:
DrawText(X,Y,color, GetFPS(), style);
Why measure once per second? Just take the time between two consecutive frames and calculate framerate from that.
Ah we-a blaze the fyah, make it bun dem!
~Syphox (05-18-2013)
Where are you handling the calculations for the fps as well? If you aren't properly checking each frame you technically will never get valid results.
The code you posted will also never work properly if you are just tossing all of it into a single function since all your variables will reset each call that is made to calculate the fps.
I was referring to the main post.