Last active
August 1, 2017 11:33
-
-
Save bit-hack/0780913ceecab4b20a289fe878d9f5e7 to your computer and use it in GitHub Desktop.
Minimal SDL 1 app skeleton
This file contains hidden or 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
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