View Full Version : Making FPS

12-26-2001, 12:34 AM
Could anybody gimme and example, how to calculate FPS in VC ++ 6 ?


12-26-2001, 01:37 AM
Use the function timeGetTime (returns time in milliseconds), and calculate the time taken to render the frame. FPS = 1/time.

12-26-2001, 05:33 AM
Originally posted by Bob:
Use the function timeGetTime (returns time in milliseconds), and calculate the time taken to render the frame. FPS = 1/time.

Thanks, i`ll try.

Leyder Dylan
12-26-2001, 11:56 AM

On my site, I've a little example for displaying FPS.

12-29-2001, 10:01 AM
Here is my function. You have to call it once every frame and then it will return the number of frames per second. Don't call it more then one time a frame because them the fps won't be correct.

#include "time.h"

int FPS()
static int frames = 0;
static int fcount = 0;
static clock_t next = clock() + 1000;


if ( clock(); >= next )
next = clock(); + 1000;
frames = fcount;
fcount = 0;

return frames;

12-29-2001, 11:10 AM
Thanks ppl. I`ve just done it myselft trough WM_TIMER.

12-29-2001, 01:09 PM
Take note that basing a timer on WM_TIMER produces a timer with somewhat variable accuracy. Why? Though the message is sent after the given delay, you don't know how much time has passed since. If you want a more accurate timer, base it on the rtc or the cpu timestamp counter.

12-29-2001, 01:45 PM
Actually, for high-resolution timing, you should use the high-performance counter. I can have triple digit framerates above 500, and still get accuracy beyond that of a float http://www.opengl.org/discussion_boards/ubb/smile.gif Lemme dig up my code... I forgot how to do it :eek: :P

Ok, create these as global variables:
LARGE_INTEGER lastQueryValue;
LARGE_INTEGER timerFrequency;

Then, in your init code:
if ( !QueryPerformanceFrequency(&timerFrequency) )
return 0; //use a different timer or abort if you get to here... fortunately you shouldn't get to here on very many machines, but it's a good idea to have a substitute available

QueryPerformanceCounter( &lastQueryValue );

And in your main loop:

QueryPerformanceCounter( &tmpValue );
lastFrameTime = (float)( tmpValue.QuadPart - lastQueryValue.QuadPart ) / (float)timerFrequency.QuadPart;
lastQueryValue = tmpValue;

Presto, instant high-res counter. And fyi, quad ints have a maximum value of 2^64, so you won't have any problem timing pretty much anything with this code http://www.opengl.org/discussion_boards/ubb/smile.gif No credit required nor desired, but you can credit me as pATCheS (please get it right :P) if you'd like.

[This message has been edited by pATChes11 (edited 12-29-2001).]

12-29-2001, 06:05 PM
Just so that genetic doesn't get confused, what patches11 (and Microsoft) call the high performance counter is in fact based on the cpu timestamp counter.

[This message has been edited by DFrey (edited 12-29-2001).]

12-30-2001, 02:17 PM
Thx ppl. i`ll remake it as you wish :-)