SDL Framerate Control

joellevin
Unregistered
 
Post: #1
Hi, I'm just looking into making a SDL-based game engine, and my initial stuff has gone well, but I need a way to control how often a frame gets drawn so my game doesn't run at 500+ fps. I would like to have redraws happen at 60 or 80 fps, how do I go about doing that?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
This won't directly help you control the frequency of drawing, but it's probably the effect you're going for: http://www.sacredsoftware.net/tutorials/...tion.xhtml
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Moderator
Posts: 1,140
Joined: 2005.07
Post: #4
If you're using OpenGL, you can also use this in SDL for vsynch:
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, TRUE);
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #5
I just used delta time instead of framerate limiting -- works much better.

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
It isn't so much to have a constant step to update your models with as to keep your computer from doing way too much work going at a very high framerate. (heating up your CPU, video card, etc. and wasting more power, not to mention the fan noise)
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
ravuya Wrote:I just used delta time instead of framerate limiting -- works much better.

I agree, it does work much better.

akb825 Wrote:It isn't so much to have a constant step to update your models with as to keep your computer from doing way too much work going at a very high framerate. (heating up your CPU, video card, etc. and wasting more power, not to mention the fan noise)
yeah its a good idea I think to have a maximum framerate, but use variable timestep within that.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
unknown Wrote:yeah its a good idea I think to have a maximum framerate, but use variable timestep within that.

There is a reason that commercial games don't use a variable timestep -- it's really bad for networking, where it helps the clients get out of sync rather than keeping them together. Using a fixed timestep makes demo recording and playback possible, fixes the amount of CPU you may have to use at a known level, means that different clients will be much closer in their simulations, makes physics much easier to code, and the list goes on.

Alex's fixed-interval tutorial is definitely the way to go.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #9
Yeah, I'm definitely a fan of fixed interval timing. It makes things far more deterministic, and easier to code.

Also, laptop users such as myself will thank you that playing your game doesn't eat their batteries for lunch. Running a game at 300fps might be an ego booster, but if you can only see 60 of those on screen anyway, what's the point of using all that extra CPU?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #10
Fixed time steps are definitely easier to deal with in the long run, but they can introduce visual glitches (stuttering/choppiness) unless you interpolate the rendered frames. Here are a couple more links (one, two) that may be helpful.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #11
Regardless of using time-based or fixed step animation, you should always VBL sync your animation in your release build. If your content is meant to be viewed by a human (as opposed to offline rendering) then there is no need to draw faster than the display refresh.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  iPhone 3GS OpenGL strange framerate bug airfire 2 3,530 Dec 2, 2009 09:22 AM
Last Post: airfire
  GLUT consistant framerate? JeroMiya 2 4,577 Apr 30, 2007 02:25 AM
Last Post: OneSadCookie
  Capping framerate unknown 18 7,795 Jul 19, 2005 04:57 AM
Last Post: unknown
  Weird framerate problem Jesse 4 3,132 Sep 1, 2003 01:01 AM
Last Post: Jesse