From c0f5e57b5ab684e111b8b05636a1ec923ebd72dc Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 2 Apr 2021 19:30:49 +0200 Subject: [PATCH] Set up a simple sdl event loop. --- 06_sdl_input/main.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/06_sdl_input/main.cpp b/06_sdl_input/main.cpp index 6120fa8..a09632a 100644 --- a/06_sdl_input/main.cpp +++ b/06_sdl_input/main.cpp @@ -6,6 +6,27 @@ #include +void main_loop_1() { + bool quit = false; + SDL_Event e; + + while (!quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) { + quit = true; + } + + if (e.type == SDL_KEYDOWN) { + printf("keydown\n"); + } + + if (e.type == SDL_KEYUP) { + printf("keyup\n"); + } + } + } +} + int main(int argv, char **args) { Renderer r; @@ -23,7 +44,7 @@ int main(int argv, char **args) { r.draw_sprite(s); r.present(); - SDL_Delay(500); + main_loop_1(); t.free(); i.free();