Sign in to follow this  

FPS Counter

This topic is 4531 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

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 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;

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 this post


Link to post
Share on other sites

This topic is 4531 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this