how to calculate fps-stuff

hi there,
i’m sorry but i am not a experienced programmer…
all i wanted to ask is : how can i measure the frames drawn in a second in my program?
i played a few weeks with opengl and windows,but now i see,when i draw many triangles and polygons and many other stuff,my application is very very slow…so i want to see a difference how much slower my program is…please let me know how you guys do this stuff…

you have to use 2 api calls :

when you initialize your program,

you call

QueryPerformanceCounter(LARGE_INTEGER *frequency).

LARGE_INTEGER is defined in windows.h and is a 64bits integer.

This will give the frequency of your computer counter in ticks/seconds

Now, before you start to draw you call

QueryPerformanceCounter(LARGE_INTEGER* count).

This will give you the count at wich the processor is.

Just before you flush everything to drawing, you call QueryPerformanceCounter again and you’ll have time it took to draw the scene in seconds like this :

frametime = (count2 / frequency) - (count1 / frequency)

the fps is 1/frametime.

you write the time to your screen, and there you go!

You can make a nice class “counter” to hide those ugly calls and LARGE_INTEGER.

in the constructor you just call the query the frequency. Don’t keep frequency it is not usefull, keep 1/frequency(and mutilply by your count value when you want to know the time, division are so slow compared to multiplication, but you should know that !)

Or, when you want to create something that’s os independant:

#include <time.h>
time_t start, end;
long frames = 0;

before your start to draw stuff:

start = time(NULL);

when your app stops:

end = time(NULL);

and each frame your increment frames:

frames++;

fps is:

fps = (float)frames/(float)(end-start);

ain’t that hard at all

Just to say the performance counter is the most precise counter on a machine.

I used this class for counting my fps:

class fps_counter
{
private:
LARGE_INTEGER *frequenz, *count_start, *count_ende;
public:
fps_counter()
{
QueryPerformanceCounter(frequenz);
*frequenz = 1 / (*frequenz);
}

void get_start_frequency()
{
	QueryPerformanceCounter(count_start);
}

void get_end_frequency()
{
	QueryPerformanceCounter(count_ende);
}

LARGE_INTEGER get_frametime()
{
	return ((*count_ende) * (*frequenz))-((*count_start) * (*frequenz));
}

} frametime;

But my compiler says:

error C2677: binary ‘/’ : no global operator defined which takes type ‘union _LARGE_INTEGER’ (or there is no acceptable conversion)

error C2676: binary ‘/’ : ‘union _LARGE_INTEGER’ does not define this operator or a conversion to a type acceptable to the predefined operator

How can I calculate my frametime now? :confused:

hi there,
i’m sorry but i am not a experienced programmer…
all i wanted to ask is : how can i measure the frames drawn in a second in my program?
i played a few weeks with opengl and windows,but now i see,when i draw many triangles and polygons and many other stuff,my application is very very slow…so i want to see a difference how much slower my program is…please let me know how you guys do this stuff…
An easy way is to use from the Fraps software. You can download it here: http://www.fraps.com/download.php
Run this program and then run your executable file.You can see the frame rate in the top-left of your window.
-Ehsan-

Originally posted by Ehsan Kamrani:

Run this program and then run your executable file.You can see the frame rate in the top-left of your window.
-Ehsan-
Nice software,thanks, but it does not solve my prob. Is there a way to convert LARGE_INTEGER to a usable format?!

long int ??

Originally posted by zukko:
long int ??
error C2440: ‘=’ : cannot convert from ‘union _LARGE_INTEGER *’ to ‘long *’

It seems as if LARGE_INTEGER is not convertable to
any type I know and my compiler (MS VC++) cant multiply LARGE_INTEGERs.

:confused:

This should work:

class fps_counter
{
private:
LARGE_INTEGER frequenz, count_start, count_ende;
public:
fps_counter()
{
QueryPerformanceCounter(&frequenz);
}

void get_start_frequency()
{
QueryPerformanceCounter(&count_start);
}

void get_end_frequency()
{
QueryPerformanceCounter(&count_ende);
}

LARGE_INTEGER get_frametime()
{
return ((count_ende.QuadPart-count_start.QuadPart)/frequenz);
}
} frametime;

get_frametime() will return milliseconds since frequenz is based on ticks per millisecond.

if you have

LARGE_INTEGER *time;

you use

time->QuadPart

it’s very simple if you read the MSDN documents
(try here )