• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# fps calculation: where to set starting and end point

## Recommended Posts

hello, i know how to calculate the fps in my mainloop...but i don''t know where to place the starting and the end points to get the time. at the moment i store the time before clearing and after blitting my buffer. thus, my fps is very low ( <= 19 fps ). i tested this in software, ie no hardware acceleration apis etc. example: for (; { gettime(t1) clear() events() blit() gettime(t2) fps = 1.0 / (t2 - t1) } did i misunderstand something ? please help me, thanks

##### Share on other sites
Yes, you have it in the right place, and the 19FPS doesn''t come from the gettime() functions, but it''s your other game related code, so go check that out.

##### Share on other sites
There''s also another method of calculating the FPS. I don''t know what you''re exactly programming with, but I assume that your compiler supports timers/interrupts or threads or something like that.

You need two variables:

int frames;int FPS;[/CODE]Or something like that...[CODE]void actualize_fps(){  FPS=frames;  frames=0;}[/CODE]The function  needs to be called automatically every second.Everytime you call the -Routine, increment frames by one.Everything you have to do is draw the FPS onto the screen then...Maybe that helps.Yours,

Indeterminatus

--si tacuisses, philosophus mansisses--

##### Share on other sites
Another way of calculating FPS is to precalculate them

For example:

int iFps=100;

##### Share on other sites
quote:

Another way of calculating FPS is to precalculate them

For example:

int iFps=100;

Priceless tip, my engine has been using int iFps = 10000; for a while now... so smooth and silky, you wouldn''t believe your eyes...

------------
- outRider -

##### Share on other sites
It was just an example After all I didnt want his engine to be as good as mine, otherwise I would have said :

int iFPS=100000;

##### Share on other sites
You should only time it AT ONE SPOT if you you want to actually measure the frame-rate - otherwise you''re timing only a portion of the framerate.

while(!exit)
{
timesnap := gettime();
fps = calcframerate(timeprev, timesnap);
timeprev = timesnap;

//Game goes here
}

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627652
• Total Posts
2978421

• 10
• 12
• 22
• 13
• 33