basic sdl loop

This commit is contained in:
Jakob Hördt 2024-08-03 02:42:49 +02:00
commit 9f82d9458c

46
main.cpp Normal file
View file

@ -0,0 +1,46 @@
#include <SDL2/SDL.h>
#include <memory>
#include <print>
template <auto sdl_destroyfunc>
using sdl_deleter_t = decltype([](auto* ptr) { sdl_destroyfunc(ptr); });
using window_t = std::unique_ptr<SDL_Window, sdl_deleter_t<SDL_DestroyWindow>>;
using surface_t = std::unique_ptr<SDL_Surface, sdl_deleter_t<SDL_FreeSurface>>;
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
}