From 9f82d9458ce6ea5896dc10ed82bab530337ede74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20H=C3=B6rdt?= <6329417-neop_@users.noreply.gitlab.com> Date: Sat, 3 Aug 2024 02:42:49 +0200 Subject: [PATCH] basic sdl loop --- main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ceba14c --- /dev/null +++ b/main.cpp @@ -0,0 +1,46 @@ + + +#include + +#include +#include + +template +using sdl_deleter_t = decltype([](auto* ptr) { sdl_destroyfunc(ptr); }); + +using window_t = std::unique_ptr>; +using surface_t = std::unique_ptr>; + +int main() { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + std::println("fuck"); + return EXIT_FAILURE; + } + + { + auto window = window_t{SDL_CreateWindow( + "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + 1024, 512, SDL_WINDOW_SHOWN + )}; + + if (!window) { + std::println( + "Window could not be created! SDL_Error: {}", SDL_GetError() + ); + return EXIT_FAILURE; + } + + auto surface = surface_t{SDL_GetWindowSurface(window.get())}; + + SDL_Event e; + bool quit = false; + while (!quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) { quit = true; } + } + } + } + + SDL_Quit(); + // leaking memory, nothing I can do +} \ No newline at end of file