Jump to content
  • Advertisement
Sign in to follow this  

Calculating FPS

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

I am trying to find out the frames per second in a game I am working on. I tried FRAPS but it won't show the FPS for my exe, I tried it with a different exe and it worked though :S. If I try running my exe in a different computer it does work. I decided to try and do it manually but the FPS won't go over 60. I was told this max could be disabled by setting vertical sync in the nvidia control panel to force off but nothing changed, oddly enough it did work for the other exe. In both computers the FPS won't go over 60 for my exe. Any thoughts/ideas? Thanks.

Share this post

Link to post
Share on other sites

Could you be accidentally setting vsync in your code?

Maybe, how does one enable vsync in code?

I looked at the thread and the fpsAccurate gives 60, the fpsInstantaneous gives 0.

unsigned float currentTick = 0;
unsigned float lastTick = 0;
unsigned float elapsedTicks = 0;

unsigned float fpsTimer = 0;
unsigned float fpsFrameCount = 0;
unsigned float fpsAccurate = 0;
unsigned float fpsInstantaneous = 0;

bool timer_start = false;
void play_state::draw()

timer_start = true;
currentTick = 0;
lastTick = 0;
elapsedTicks = 0;

currentTick = lastTick = timeGetTime();

lastTick = currentTick;
currentTick = timeGetTime();
elapsedTicks = currentTick - lastTick;

float elapsedTime = elapsedTicks / 1000.f;

fpsTimer += elapsedTicks;
if ( fpsTimer >= 10000 ) {
fpsAccurate = fpsFrameCount;
fpsFrameCount = 0;
fpsTimer = 0;

if ( elapsedTicks )
fpsInstantaneous = 1000 / elapsedTicks;

Share this post

Link to post
Share on other sites
By the way, you can get more accurate time values using QueryPerformanceCounter.

Here's a useful piece of code I found.

#pragma once
#include <windows.h>

/// Create a Timer, which will immediately begin counting
/// up from 0.0 seconds.
/// You can call reset() to make it start over.
class Timer {
Timer() {
/// reset() makes the timer start over counting from 0.0 seconds.
void reset() {
unsigned __int64 pf;
QueryPerformanceFrequency( (LARGE_INTEGER *)&pf );
freq_ = 1.0 / (double)pf;
QueryPerformanceCounter( (LARGE_INTEGER *)&baseTime_ );
/// seconds() returns the number of seconds (to very high resolution)
/// elapsed since the timer was last created or reset().
double seconds() {
unsigned __int64 val;
QueryPerformanceCounter( (LARGE_INTEGER *)&val );
return (val - baseTime_) * freq_;
/// seconds() returns the number of milliseconds (to very high resolution)
/// elapsed since the timer was last created or reset().
double milliseconds() {
return seconds() * 1000.0;
double freq_;
unsigned __int64 baseTime_;

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!