# FPS Counter

This topic is 4935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Anyone know how to implement an FPS Counter? Thanks!

##### Share on other sites
Here

Or use something like this (This will show up in the title bar of the window):
//Calculate Framerate::http://www.gametutorials.net/void CalculateFrameRate(){	static float framesPerSecond = 0.0f;    static float lastTime = 0.0f;    float currentTime = GetTickCount()*0.001f;    ++framesPerSecond;    if( currentTime - lastTime > 1.0f )    {	    lastTime = currentTime;	    if(!Option.fullscreen)	    {		    sprintf(strFrameRate, "Program Title | FPS: %d", int(framesPerSecond));		    SetWindowText(hwnd, strFrameRate);            }        else        {            //Display in Game        }        framesPerSecond = 0;    }}

##### Share on other sites
using QueryPerformanceFrequency() and QueryPerformanceCounter() declared as a LONG_INTEGER in direct x is a way, the long integer is used as you may be dealing with a lot of numbers

then you would need something like

then a getfucntion could be called which divides the resulting delta and freq quad parts

##### Share on other sites
Thanks for the help. Here is what I've come up with:

#define FPSUPDATETIME 50 // Number of ms until FPS is updatedDWORD StartTime = 0;DWORD DeltaTime = 0;DWORD LastTime = 0;DWORD FPS_Time = 0;DWORD FPS_Frames = 0;DWORD FPS_FinalFrames = 0;while(true){    // Setup RTS    StartTime = GetTickCount();    DeltaTime = StartTime - LastTime;    if(DeltaTime > SAFETIME)        DeltaTime = SAFETIME;    LastTime = StartTime;    // Calculate FPS    FPS_Time += DeltaTime;    ++FPS_Frames;    if(FPS_Time >= FPSUPDATETIME)    {        FPS_FinalFrames = FPS_Frames * (1000 / FPSUPDATETIME);        FPS_Time        -= FPSUPDATETIME;        FPS_Frames      = 0;    }    /* Display FPS_FinalFrames here */    /* Perform other game-related processes below this */}

How's it look? The timer seems to be extremely innaccurate at a 50ms update time.

##### Share on other sites
I wouldn't use GetTickCount if I were you, it can be off by up to 55ms.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 34
• 16
• 11
• 12
• ### Forum Statistics

• Total Topics
634123
• Total Posts
3015650
×