Advertisement Jump to content
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts


Or use something like this (This will show up in the title bar of the window):

//Calculate Framerate::
void CalculateFrameRate()
static float framesPerSecond = 0.0f;
static float lastTime = 0.0f;
float currentTime = GetTickCount()*0.001f;
if( currentTime - lastTime > 1.0f )
lastTime = currentTime;
sprintf(strFrameRate, "Program Title | FPS: %d", int(framesPerSecond));
SetWindowText(hwnd, strFrameRate);
//Display in Game
framesPerSecond = 0;

Share this post

Link to post
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

Delta.QuadPart = Timer.QuadPart - LastQuery.QuadPart;
LastQuery.QuadPart = Timer.QuadPart;

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

Share this post

Link to post
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 updated

DWORD StartTime = 0;
DWORD DeltaTime = 0;
DWORD LastTime = 0;
DWORD FPS_Time = 0;
DWORD FPS_Frames = 0;
DWORD FPS_FinalFrames = 0;

// Setup RTS
StartTime = GetTickCount();
DeltaTime = StartTime - LastTime;

if(DeltaTime > SAFETIME)
DeltaTime = SAFETIME;

LastTime = StartTime;

// Calculate FPS
FPS_Time += DeltaTime;

FPS_FinalFrames = FPS_Frames * (1000 / 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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!