The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
FPS
Thiago Nunes Leite
Guest

How do i create a fps count for my 2d game using sdl, also what can i do to lock it? thanks...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060121/49116968/attachment.htm
FPS
Mike Powell
Guest

Thiago Nunes Leite wrote:

Quote:
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.
FPS
Thiago Nunes Leite
Guest

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

----- Original Message -----
From: "Mike Powell" <belar at sevensouth.com>
To: "A list for developers using the SDL library. (includes SDL-announce)"
<sdl at libsdl.org>
Sent: Saturday, January 21, 2006 4:09 AM
Subject: Re: [SDL] FPS


Quote:
Thiago Nunes Leite wrote:

Quote:
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
FPS
Brian Barrett
Guest

On 1/21/06, Thiago Nunes Leite <luthi at sili.com.br> wrote:
Quote:
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;
FPS
Martin Wegner
Guest

Hello.

Thiago Nunes Leite wrote:
Quote:
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

Quote:
[...]

--
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
FPS
Alan Wolfe
Guest

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: "Thiago Nunes Leite" <luthi at sili.com.br>
To: "A list for developers using the SDL library. (includesSDL-announce)"
<sdl at libsdl.org>
Sent: Saturday, January 21, 2006 7:03 AM
Subject: Re: [SDL] FPS


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

----- Original Message -----
From: "Mike Powell" <belar at sevensouth.com>
To: "A list for developers using the SDL library. (includes SDL-announce)"
<sdl at libsdl.org>
Sent: Saturday, January 21, 2006 4:09 AM
Subject: Re: [SDL] FPS


Quote:
Thiago Nunes Leite wrote:

Quote:
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