46 lines
No EOL
975 B
C++
46 lines
No EOL
975 B
C++
|
|
|
|
#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
|
|
} |