[SDL] FPS Counter?

DARKGuy . dark.guy.2008 at gmail.com
Thu Sep 14 10:59:59 PDT 2006


Hey! ^^

o.o yay! that works prefectly! :D yeah, I heard about there could be some
divide-by-zero errors but no way how to avoid that one either, now I'm
getting the hang of it too, thanks! :D :D :D

On 9/14/06, Peter Mulholland <darkmatter at freeuk.com> wrote:
>
> Hello DARKGuy,
>
> Thursday, September 14, 2006, 6:24:53 PM, you wrote:
>
> > Hi again! xD... my game's progressing awesomely thanks to all of you ^_^
> > hehe... o.o but now I wonder xD I've been through google, lazy foo's
> > tutorials, Aaron's SDL tutorials, and such, searching for an FPS counter
> > code and I haven't found any, and in lazy foo's site the code is too old
> and
> > it throws errors in SDL (it uses "timers"? which I supposed SDL had =/
> ).
> > Going through google all I can find are pseudo-codes and theories, but
> no
> > example whatsoever :(. Does anybody here has a simple FPS counter that
> can
> > share please? ^^...
>
>
> It's quite easy:
>
> while (gamerunning)
> {
>       Uint32 start_time, frame_time;
>       float fps;
>
>       start_time = SDL_GetTicks();
>
>       // do stuff
>       SDL_Flip();
>
>       frame_time = SDL_GetTicks()-start_time;
>       fps = (frame time > 0) ? 1000.0f / frame_time : 0.0f;
> }
>
> The extra bit in the fps calculation stops a divide by zero should a
> frame happen to take less than a millisecond (it's not likely, but it
> can happen)
>
> --
> Best regards,
> Peter                            mailto:darkmatter at freeuk.com
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060914/2a0244bf/attachment-0008.htm>


More information about the SDL mailing list