Capping framerate

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
Yeah, just wondering if it would be a good idea to have a maximum framerate,
the thing is though ive not seen it done in SDL anywhere so maybe its a bad thing to do,

My current run loop code is

Code:
while(1) {
    while(SDL_PollEvent(&event)) {
        switch (event.type) {
            case SDL_KEYDOWN:
                SDL_Quit();
                return 1;
                break;
            default:
                break;
        }
    }
    drawGL();
}

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
It's not a bad idea, it certainly makes coding a little easier. If this is for the same 2D game you've been asking about, then I would probably say yes.

You *could* be drawing at 300fps, but what would be the point? At most, you are going to see enough frames as the refresh rate. An even better idea would be to enable VBL sync, which waits for the monitor to refresh before swapping buffers. 2D games can look awful with this turned off if they are fast moving.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
It is the same game.
Well with a 75Hz monitor 300fps is 225 frames that you dont see so yeah, not much pont.

VBL sync, is that an SDL thing?

What would be the best way to capp framerate?
Some example code would be so useful.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
Search the forums. All of your recent questions have been discussed here before.

For example, SDL VBL.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
So is VBL going to work multiplatorm?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
The method of forcing VBL sync will differ per platform.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
Oh right, thats not really a problem it just means a bit more coding then.
But would forcing a maximum framerate of about 60 do kinda a similar thing?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #8
No, generating 60 fps is not the same thing as making sure the page flip happens when the screen isn't refreshing. If you generate exactly 60 fps but don't sync to VBL you'll have a nice stationary tear running across your content.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #9
Ahhh, I understand now.
Right and will that happen regarless of whether im rendering usng OpenGL or somthing else?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #10
Yes - it's about redrawing the screen while the screen buffer is updated - half of the screen will be this frame, but the rest will be the last frame you displayed.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #11
yeah, that seems like it would be a big problem but why dont I see code for this in any other games?
Does anyone have SDL code for this that would work multiplatorm, or even can It be ahcieved with multipatform with SDL?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
There is currently no way to enable VBL using SDL. You'll have to have code for each system.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #13
hmmmm, I could use a ./configure to fix the code for each OS.
It might be tricky but Ill see what I can do.

thanks a lot for the help Skorche, arekkusu, Fenris!

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #14
unknown Wrote:hmmmm, I could use a ./configure to fix the code for each OS.
It might be tricky but Ill see what I can do.

thanks a lot for the help Skorche, arekkusu, Fenris!

Just use #ifdef, enabling VBL on Mac is just 2 lines of code...
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #15
What two lines?

Sir, e^iπ + 1 = 0, hence God exists; reply!
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,456 Dec 2, 2009 09:22 AM
Last Post: airfire
  GLUT consistant framerate? JeroMiya 2 4,509 Apr 30, 2007 02:25 AM
Last Post: OneSadCookie
  SDL Framerate Control joellevin 10 8,399 Jan 4, 2007 01:26 PM
Last Post: arekkusu
  Weird framerate problem Jesse 4 3,077 Sep 1, 2003 01:01 AM
Last Post: Jesse