Created
January 2, 2013 23:32
-
-
Save iKlsR/4439377 to your computer and use it in GitHub Desktop.
boilerplate for sdl.. (portable..)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL/SDL.h> | |
void _dispatch(SDL_Event e, bool * r) { | |
while (SDL_PollEvent (&e)) { | |
switch (e.type) { | |
case SDL_QUIT: | |
*r = false; | |
break; | |
} | |
} | |
} | |
void _regulate(int f, Uint32 s) { | |
if (1000/ f > SDL_GetTicks() - s) | |
SDL_Delay(1000/ f - (SDL_GetTicks() - s)); | |
} | |
int main(int argc, char ** argv) { | |
putenv("SDL_VIDEO_CENTERED=1"); | |
SDL_Init(SDL_INIT_EVERYTHING); | |
SDL_WM_SetCaption("app", 0); | |
SDL_Surface * screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); | |
bool running = true; | |
const int fps = 100/ 3; | |
Uint32 start; | |
while (running) { | |
start = SDL_GetTicks(); | |
SDL_Event event; | |
_dispatch(event, &running); | |
SDL_Flip(screen); | |
_regulate(fps, start); | |
} | |
SDL_Quit(); | |
return 0x00; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment