[SDL] FPS
Brian Barrett
brian.ripoff at gmail.com
Sat Jan 21 09:55:53 PST 2006
On 1/21/06, Thiago Nunes Leite <luthi at sili.com.br> wrote:
> Yes I know, I'm using SFont for handling fonts. My problem is how do i count
> fps?
each time you draw thats a frame. so just make an int outside the
loop, increment it every frame. store SDL_GetTicks() when you just
enter the mainloop.
so your main loop looks something like this:
int numFrames = 0;
Uint32 startTime = SDL_GetTicks();
while( gameRunning() )
{
getInput();
updateObjects();
drawObjects();
++numFrames;
}
at any point when you want to know the average fames per second, use
this calculation
float fps = ( numFrames/(float)(SDL_GetTicks() - startTime) )*1000;
More information about the SDL
mailing list