Fps

How do i create a fps count for my 2d game using sdl, also what can i do to lock it? thanks…

Thiago Nunes Leite wrote:

How do i create a fps count for my 2d game using sdl, also what can i
do to lock it? thanks…

In order to setup an onscreen counter, you need a way to display text.
This is not built in to SDL, but there are hundreds of ways to do it. I
use a GUI system called GUIchan myself (guichan.sourceforge.net).

Alternately, you could just use fprintf(stdout) to output the average
framerate to sdlout.txt. Not a very good solution, for most
applications, but an easy answer for simple apps or tech demos.

There is no easy solution for locking the framerate. Obviously if you’re
rendering faster then the monitor’s refresh rate, that will serve as a
limiting factor. Otherwise, you’ll just have to insert some sort of wait
command on each frame to make sure the requesite amount of time has
passed since the last frame was rendered.

Oh, and if you haven’t figured it out, to calculate the frame rate and
other timing issues, you want to use the “Timers” subsystem. Check the
documentation for the details on that.

Yes I know, I’m using SFont for handling fonts. My problem is how do i count
fps?> ----- Original Message -----

From: belar@sevensouth.com (Mike Powell)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Saturday, January 21, 2006 4:09 AM
Subject: Re: [SDL] FPS

Thiago Nunes Leite wrote:

How do i create a fps count for my 2d game using sdl, also what can i do
to lock it? thanks…

In order to setup an onscreen counter, you need a way to display text.
This is not built in to SDL, but there are hundreds of ways to do it. I
use a GUI system called GUIchan myself (guichan.sourceforge.net).

Alternately, you could just use fprintf(stdout) to output the average
framerate to sdlout.txt. Not a very good solution, for most applications,
but an easy answer for simple apps or tech demos.

There is no easy solution for locking the framerate. Obviously if you’re
rendering faster then the monitor’s refresh rate, that will serve as a
limiting factor. Otherwise, you’ll just have to insert some sort of wait
command on each frame to make sure the requesite amount of time has passed
since the last frame was rendered.

Oh, and if you haven’t figured it out, to calculate the frame rate and
other timing issues, you want to use the “Timers” subsystem. Check the
documentation for the details on that.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

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;On 1/21/06, Thiago Nunes Leite wrote:

Yes I know, I’m using SFont for handling fonts. My problem is how do i count
fps?

Hello.

Thiago Nunes Leite wrote:

Yes I know, I’m using SFont for handling fonts. My problem is how do i
count fps?

I guess you have a main loop in your game. Each iteration the screen is
cmopletely redrawn so the only thing you have to do is count the
iterations per second (using ctime, ticks, whatever).

Regards, martin> […]


Get my public GPG key from pgp.mit.edu or wwwkeys.pgp.net
Key ID: 0x44085D12

Homepage: http://mroot.net/
Powered by Gentoo Linux (http://gentoo.org/)

-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 890 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060121/360951b5/attachment.pgp

You can use SDL_GetTicks() every frame to measure the number of miliseconds
between frames, then you divide 1000 by that number to get your frames per
second, super simple (:> ----- Original Message -----

From: luthi@sili.com.br (Thiago Nunes Leite)
To: "A list for developers using the SDL library. (includesSDL-announce)"

Sent: Saturday, January 21, 2006 7:03 AM
Subject: Re: [SDL] FPS

Yes I know, I’m using SFont for handling fonts. My problem is how do i
count fps?

----- Original Message -----
From: “Mike Powell”
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Saturday, January 21, 2006 4:09 AM
Subject: Re: [SDL] FPS

Thiago Nunes Leite wrote:

How do i create a fps count for my 2d game using sdl, also what can i do
to lock it? thanks…

In order to setup an onscreen counter, you need a way to display text.
This is not built in to SDL, but there are hundreds of ways to do it. I
use a GUI system called GUIchan myself (guichan.sourceforge.net).

Alternately, you could just use fprintf(stdout) to output the average
framerate to sdlout.txt. Not a very good solution, for most applications,
but an easy answer for simple apps or tech demos.

There is no easy solution for locking the framerate. Obviously if you’re
rendering faster then the monitor’s refresh rate, that will serve as a
limiting factor. Otherwise, you’ll just have to insert some sort of wait
command on each frame to make sure the requesite amount of time has
passed since the last frame was rendered.

Oh, and if you haven’t figured it out, to calculate the frame rate and
other timing issues, you want to use the “Timers” subsystem. Check the
documentation for the details on that.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl