From 6d0de7e62173a953be9cc0bc7ec8a9d86dc4ac0d Mon Sep 17 00:00:00 2001 From: BadQuanta Date: Mon, 20 Apr 2026 11:00:42 +0000 Subject: [PATCH] Initial scaffolding. --- CMakeLists.txt | 38 ++++++++++++++++++++++++++++ examples/CMakeLists.txt | 4 +++ examples/HelloWorld.cpp | 27 ++++++++++++++++++++ include/hdk/sdl.hpp | 9 +++++++ include/hdk/sdl/video/Renderer.hpp | 0 include/hdk/sdl/video/Surface.hpp | 0 include/hdk/sdl/video/Window.hpp | 40 ++++++++++++++++++++++++++++++ 7 files changed, 118 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 examples/CMakeLists.txt create mode 100644 examples/HelloWorld.cpp create mode 100644 include/hdk/sdl.hpp create mode 100644 include/hdk/sdl/video/Renderer.hpp create mode 100644 include/hdk/sdl/video/Surface.hpp create mode 100644 include/hdk/sdl/video/Window.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..efa2c7d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.20) +project(hdk-sdl + VERSION 0.0.0 + LANGUAGES CXX +) + +# hdk-sdl OPTIONS +option(HDK_SDL_BUILD_TESTS "Build hdk-sdl tests" OFF) +# TODO: Unit testing +if(HDK_SDL_BUILD_TESTS) + message(WARNING "hdk-sdl tests are not implemented yet.") +endif() +option(HDK_SDL_BUILD_EXAMPLES "Build hdk-sdl examples" OFF) +if(HDK_SDL_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() +option(HDK_SDL_BUILD_COVERAGE "Build hdk-sdl with coverage reporting enabled" OFF) +if(HDK_SDL_BUILD_COVERAGE) + message(WARNING "hdk-sdl coverage testing is not implemented yet.") +endif() +# TODO: Coverage testing + +# FOR SDL Building +set(SDL_TEST OFF CACHE BOOL "Disable SDL tests" FORCE) +set(SDL_EXAMPLES OFF CACHE BOOL "Disable SDL examples" FORCE) +set(SDL_INSTALL OFF CACHE BOOL "Disable SDL install" FORCE) +# NOTE: Possibly disable SDL_PIPEWIRE and/or SDL_PIPEWIRE_SHARED? +include(FetchContent) +FetchContent_Declare( + SDL3 + GIT_REPOSITORY http://github.com/libsdl-org/SDL.git + GIT_TAG release-3.4.0 +) +FetchContent_MakeAvailable(SDL3) +add_library(hdk-sdl INTERFACE) +target_link_libraries(hdk-sdl INTERFACE SDL3::SDL3 hdk-grid) +target_include_directories(hdk-sdl INTERFACE ${SDL3_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include) + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..558053d --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,4 @@ +# Simple examples for using hdk-sdl. + +add_executable(HelloWorld HelloWorld.cpp) +target_link_libraries(HelloWorld PRIVATE hdk-sdl) \ No newline at end of file diff --git a/examples/HelloWorld.cpp b/examples/HelloWorld.cpp new file mode 100644 index 0000000..9050845 --- /dev/null +++ b/examples/HelloWorld.cpp @@ -0,0 +1,27 @@ +#include + +using namespace hdk::sdl; + +Window window { nullptr }; +//Renderer renderer { nullptr }; + +int main(int argc, char* argv[]) +{ + window = Window::Create("Hello World", 800, 600, 0); + if (!window) { + SDL_Log("Failed to create window: %s", SDL_GetError()); + return 1; + } + // + SDL_Event event; + bool running = true; + while (running) { + while (SDL_PollEvent(&event)) { + if (event.type == SDL_EVENT_QUIT) { + running = false; + } + } + } + window = nullptr; // Explicitly release the window before quitting SDL + return 0; +} \ No newline at end of file diff --git a/include/hdk/sdl.hpp b/include/hdk/sdl.hpp new file mode 100644 index 0000000..52a2a52 --- /dev/null +++ b/include/hdk/sdl.hpp @@ -0,0 +1,9 @@ +#pragma once +/** + * @file sdl.hpp + * @brief HDK - SDL Frontend API + **/ + +#include +// TODO #include +// TODO #include diff --git a/include/hdk/sdl/video/Renderer.hpp b/include/hdk/sdl/video/Renderer.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/hdk/sdl/video/Surface.hpp b/include/hdk/sdl/video/Surface.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/hdk/sdl/video/Window.hpp b/include/hdk/sdl/video/Window.hpp new file mode 100644 index 0000000..d8a8b6f --- /dev/null +++ b/include/hdk/sdl/video/Window.hpp @@ -0,0 +1,40 @@ +#pragma once +/** + * @file Window.hpp + * @brief HDK sdl video header only wrapper for SDL_Window struct & related functions + */ +#include +#include +/** Windows are the primary interface for rendering and interacting with the user in SDL */ +namespace hdk::sdl { +class Window : public hdk::grid::SharedPtrWrapper { +public: + /** Inherit constructors from SharedPtrWrapper */ + using hdk::grid::SharedPtrWrapper::SharedPtrWrapper; + /** + * https://wiki.libsdl.org/SDL3/SDL_CreateWindow + * https://wiki.libsdl.org/SDL3/SDL_DestroyWindowSurface + * + * @param title The title of the window, in UTF-8 encoding. If the title contains UTF-8 characters, you should use SDL_CreateWindowUTF8() instead. + * @param w The width of the window in pixels. + * @param h The height of the window in pixels. + * @param flags 0, or one or more SDL_WindowFlags OR'd together. + * @return A Window instance that manages the created SDL_Window. If window creation fails, the returned Window will evaluate to false (i.e., it will be null). + */ + static Window Create(const char* title, int w, int h, SDL_WindowFlags flags) + { + return Window(get_or_cache(SDL_CreateWindow(title, w, h, flags), SDL_DestroyWindow)); + } + /** + * https://wiki.libsdl.org/SDL3/SDL_GetWindowFromID + * @brief Get window for WindowID + * @param id The ID of the window. + * @return A Window instance that wraps the SDL_Window. If no window with the given ID exists, the returned Window will evaluate to false (i.e., it will be null). + */ + static Window GetFromID(SDL_WindowID id) + { + /** Because it is possible windows were created by other means, we use get_or_view to wrap the SDL_Window without taking ownership */ + return Window(get_or_view(SDL_GetWindowFromID(id))); + } +}; +} \ No newline at end of file