diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e1ea9b..a76a08b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,10 @@ project(HansTheGatherer) # Option to switch real platform vs. SDL implementation... find_package(SDL3 REQUIRED) +find_package(spdlog REQUIRED) add_executable(HansTheGatherer main.cpp) -target_link_libraries(HansTheGatherer SDL3::SDL3) +target_link_libraries(HansTheGatherer SDL3::SDL3 spdlog::spdlog) -set_property(TARGET HansTheGatherer PROPERTY CXX_STANDARD 23) +set_property(TARGET HansTheGatherer PROPERTY CXX_STANDARD 20) diff --git a/main.cpp b/main.cpp index 1c35fee..46ec4f4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,52 @@ -#include #include +#include +#include +#include + +const uint8_t image_data[] = +{ +#embed "main.cpp" +}; auto main() -> int { - std::println("Hello World!"); + spdlog::info("Initialize SDL..."); + bool sdl_success = SDL_Init(SDL_INIT_VIDEO); + if (!sdl_success) { + spdlog::critical("Failed to initialize SDL!\nCause: {}", SDL_GetError()); + std::terminate(); + } + + auto *sdl_window = SDL_CreateWindow("HansTheGatherer", 400, 280, 0); + if (sdl_window == nullptr) { + spdlog::critical("Failed to create SDL window!\nCause: {}", SDL_GetError()); + } + + auto *sdl_renderer = SDL_CreateRenderer(sdl_window, nullptr); + if (sdl_renderer == nullptr) { + spdlog::critical("Failed to create SDL renderer!\nCause: {}", + SDL_GetError()); + } + + bool exit_gameloop = false; + while (!exit_gameloop) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_EVENT_QUIT: + exit_gameloop = true; + break; + case SDL_EVENT_KEY_DOWN: + if (event.key.key == SDLK_ESCAPE) { + exit_gameloop = true; + } + break; + } + } + } + + SDL_DestroyRenderer(sdl_renderer); + SDL_DestroyWindow(sdl_window); + SDL_Quit(); + return 0; }