basic sdl loop
This commit is contained in:
commit
9f82d9458c
1 changed files with 46 additions and 0 deletions
46
main.cpp
Normal file
46
main.cpp
Normal 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
|
||||
}
|
Loading…
Reference in a new issue