/sdl

Header-only C++23 wrapper for SDL 2.30 [WIP]

Primary LanguageC++MIT LicenseMIT

SDL

Header-only C++23 wrapper for SDL 2.30.

Building the tests

  • Run bootstrap.[bat|sh]. This will install doctest + sdl, and create the project under the ./build directory.
  • Run cmake on the ./build directory and toggle SDL_BUILD_TESTS.
  • Configure, generate, make.

Using

The cmake project exports the sdl::sdl target, hence you can:

find_package         (sdl CONFIG REQUIRED)
target_link_libraries([YOUR_PROJECT_NAME] PRIVATE sdl::sdl)

And then point the sdl_DIR to the build or installation directory. Alternatively, you can copy the contents of the include folder to your project.

Design notes

  • Functions:
    • The order of parameters are identical to the SDL with the following exception:
      • Parameters with default values are moved to the end of the function, and are ordered from the most to least likely to be changed.
  • Error Handling:
    • This library does not throw exceptions, except for the exceptions thrown due to standard library usage.
    • Errors are propagated to the caller using std::expected<T, std::string>, the unexpected state containing the result of sdl::error().
    • Error handling is performed if the documentation of the native function specifies an error state.
  • Versioning:
    • The major, minor and patch version are identical to the supported version of SDL.

Coverage by headers

  • SDL.h
  • SDL_assert.h
  • SDL_atomic.h
  • SDL_audio.h
  • SDL_bits.h
  • SDL_blendmode.h
  • SDL_clipboard.h
  • SDL_config.h (Reason: Nothing to wrap.)
  • SDL_config.h.cmake (Reason: Nothing to wrap.)
  • SDL_config.h.in (Reason: Nothing to wrap.)
  • SDL_config_android.h (Reason: Nothing to wrap.)
  • SDL_config_emscripten.h (Reason: Nothing to wrap.)
  • SDL_config_iphoneos.h (Reason: Nothing to wrap.)
  • SDL_config_macosx.h (Reason: Nothing to wrap.)
  • SDL_config_minimal.h (Reason: Nothing to wrap.)
  • SDL_config_ngage.h (Reason: Nothing to wrap.)
  • SDL_config_os2.h (Reason: Nothing to wrap.)
  • SDL_config_pandora.h (Reason: Nothing to wrap.)
  • SDL_config_windows.h (Reason: Nothing to wrap.)
  • SDL_config_wingdk.h (Reason: Nothing to wrap.)
  • SDL_config_winrt.h (Reason: Nothing to wrap.)
  • SDL_config_xbox.h (Reason: Nothing to wrap.)
  • SDL_copying.h (Reason: Nothing to wrap.)
  • SDL_cpuinfo.h
  • SDL_egl.h (Reason: Use a dedicated EGL wrapper such as matus-chochlik/eagine-eglplus instead.)
  • SDL_endian.h
  • SDL_error.h
  • SDL_events.h
  • SDL_filesystem.h
  • SDL_gamecontroller.h
  • SDL_gesture.h
  • SDL_guid.h
  • SDL_haptic.h
  • SDL_hidapi.h
  • SDL_hints.h
  • SDL_joystick.h
  • SDL_keyboard.h
  • SDL_keycode.h
  • SDL_loadso.h
  • SDL_locale.h
  • SDL_log.h
  • SDL_main.h
  • SDL_messagebox.h
  • SDL_metal.h
  • SDL_misc.h
  • SDL_mouse.h
  • SDL_mutex.h
  • SDL_name.h (Reason: Nothing to wrap.)
  • SDL_opengl.h (Reason: Use a dedicated OpenGL wrapper such as acdemiralp/gl instead.)
  • SDL_opengl_glext.h (Reason: Use a dedicated OpenGL wrapper instead.)
  • SDL_opengles.h (Reason: Use a dedicated OpenGL ES wrapper instead.)
  • SDL_opengles2.h (Reason: Use a dedicated OpenGL ES wrapper instead.)
  • SDL_opengles2_gl2platform.h (Reason: Use a dedicated OpenGL ES wrapper instead.)
  • SDL_opengles2_khrplatform.h (Reason: Use a dedicated OpenGL ES wrapper instead.)
  • SDL_pixels.h
  • SDL_platform.h
  • SDL_power.h
  • SDL_quit.h
  • SDL_rect.h
  • SDL_render.h
  • SDL_revision.h
  • SDL_revision.h.cmake (Reason: Nothing to wrap.)
  • SDL_rwops.h
  • SDL_scancode.h
  • SDL_sensor.h
  • SDL_shape.h
  • SDL_stdinc.h
  • SDL_surface.h
  • SDL_system.h
  • SDL_syswm.h
  • SDL_test.h (Reason: Use a dedicated testing library such as onqtam/doctest instead.)
  • SDL_test_assert.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_common.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_compare.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_crc32.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_font.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_fuzzer.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_harness.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_images.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_log.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_md5.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_memory.h (Reason: Use a dedicated testing library instead.)
  • SDL_test_random.h (Reason: Use a dedicated testing library instead.)
  • SDL_thread.h
  • SDL_timer.h
  • SDL_touch.h
  • SDL_types.h (Reason: Nothing to wrap.)
  • SDL_version.h
  • SDL_video.h
  • SDL_vulkan.h
  • begin_code.h (Reason: Nothing to wrap.)
  • close_code.h (Reason: Nothing to wrap.)

Future work

  • Evaluate each use of std::expected<type, std::string> and determine if it should be replaced with a type with invalid content.
  • Consider a detail namespace or separate namespaces for headers to reduce and organize the information presented by intellisense.
  • Examples and higher-level abstractions:
    • In particular, a micro application engine consisting of the following abstractions, gathering the content of SDL into several system monoliths:
      • engine
      • system
        • audio_system
        • display_system
        • input_system
        • rendering_system
        • time_system
  • Tests.