Skip to content

Instantly share code, notes, and snippets.

@iKlsR
Created January 2, 2013 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iKlsR/4439377 to your computer and use it in GitHub Desktop.
Save iKlsR/4439377 to your computer and use it in GitHub Desktop.
boilerplate for sdl.. (portable..)
#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