Skip to content

Instantly share code, notes, and snippets.

@bit-hack
Last active August 1, 2017 11:33
Show Gist options
  • Save bit-hack/0780913ceecab4b20a289fe878d9f5e7 to your computer and use it in GitHub Desktop.
Save bit-hack/0780913ceecab4b20a289fe878d9f5e7 to your computer and use it in GitHub Desktop.
Minimal SDL 1 app skeleton
struct Framework {
Framework()
: _screen(NULL)
{
}
bool init(uint32_t w, uint32_t h)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
return false;
}
_screen = SDL_SetVideoMode(w, h, 32, 0);
if (!_screen) {
return false;
}
return true;
}
bool eventPump()
{
if (_screen) {
SDL_Flip(_screen);
SDL_FillRect(_screen, NULL, 0x202020);
}
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
return false;
}
}
SDL_Delay(20);
return true;
}
int main()
{
if (!init(320, 200)) {
return 1;
}
while (eventPump()) {
// do something
}
return 0;
}
protected:
SDL_Surface* _screen;
};
int main()
{
Framework app;
return app.main();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment