• ### Announcements

#### Archived

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

# SDL FPS counter

## 2 posts in this topic

I''ve looked around but alas, no websites pertaining to creating an FPS counter in SDL. (Well their must be some out there, but I just couldn''t pull them up with Google...) All I did find was SDL_GetTicks(), which is supposed to count the number of milliseconds since the SDL library was called. The only problem with this is that it has a resolution of only 10ms under windows - and I don''t know what that means. So what should I do? I don''t need the FPS counter really, although I''d like to put one in this and any other SDL app I make just as a performance tester. What I really need is a way of limiting how fast the main loop loops so that my apps don''t run really fast on really fast machines and really slow on really slow machines. An idea I have is to limit the number of times the loop goes through in one second to under 60 - but I still do not know how to implement that. How would I "slow" down the loop? Help me out! Thanks!
0

##### Share on other sites
A much better approach to making the game run at consistent speeds is to make movement in your game time-dependent. Rather than updating something''s position/velocity by a fixed amount each frame, update position by velocity*timeElapsedSinceLastFrame and update velocity by acceleration*timeElapsedSinceLastFrame. You calculate timeElapsedSinceLastFrame using SDL_GetTicks.
0

##### Share on other sites

    // setup codeUint32 startclock = 0;Uint32 deltaclock = 0;Uint32 currentFPS = 0;// at beginning of loopstartclock = SDL_GetTicks();// actual fps calculation inside loopdeltaclock = SDL_GetTicks() - startclock;startclock = SDL_GetTicks();		if ( deltaclock != 0 )	currentFPS = 1000 / deltaclock;

- jeremiah

inlovewithGod.com

[edited by - keethrus on March 4, 2003 4:23:27 PM]
0