{"id":13418998,"url":"https://github.com/libSDL2pp/libSDL2pp","last_synced_at":"2025-03-15T04:31:13.773Z","repository":{"id":10458086,"uuid":"12629793","full_name":"libSDL2pp/libSDL2pp","owner":"libSDL2pp","description":"C++ bindings/wrapper for SDL2","archived":false,"fork":false,"pushed_at":"2023-12-11T15:52:32.000Z","size":1179,"stargazers_count":562,"open_issues_count":39,"forks_count":89,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-10-30T10:03:25.508Z","etag":null,"topics":["c-plus-plus","gamedev","graphics","sdl","sdl-image","sdl-mixer","sdl-ttf","sdl2"],"latest_commit_sha":null,"homepage":"https://sdl2pp.amdmi3.ru","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libSDL2pp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"COPYING.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-09-05T21:48:26.000Z","updated_at":"2024-10-10T11:22:05.000Z","dependencies_parsed_at":"2024-04-12T04:44:23.705Z","dependency_job_id":"4f18f815-e957-4694-a158-dfeb6c32b9f7","html_url":"https://github.com/libSDL2pp/libSDL2pp","commit_stats":null,"previous_names":["amdmi3/libsdl2pp"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libSDL2pp%2FlibSDL2pp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libSDL2pp%2FlibSDL2pp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libSDL2pp%2FlibSDL2pp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libSDL2pp%2FlibSDL2pp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libSDL2pp","download_url":"https://codeload.github.com/libSDL2pp/libSDL2pp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243685506,"owners_count":20330980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","gamedev","graphics","sdl","sdl-image","sdl-mixer","sdl-ttf","sdl2"],"created_at":"2024-07-30T22:01:09.943Z","updated_at":"2025-03-15T04:31:13.410Z","avatar_url":"https://github.com/libSDL2pp.png","language":"C++","readme":"\u003ca href=\"https://repology.org/metapackage/libsdl2pp/versions\"\u003e\n    \u003cimg src=\"https://repology.org/badge/vertical-allrepos/libsdl2pp.svg\" alt=\"libsdl2pp packaging status\" align=\"right\"\u003e\n\u003c/a\u003e\n\n[![CI](https://github.com/libSDL2pp/libSDL2pp/actions/workflows/ci.yml/badge.svg)](https://github.com/libSDL2pp/libSDL2pp/actions/workflows/ci.yml)\n[![Github commits (since latest release)](https://img.shields.io/github/commits-since/libSDL2pp/libSDL2pp/latest.svg)](https://github.com/libSDL2pp/libSDL2pp)\n\n# libSDL2pp\n\nThis library provides C++ bindings/wrapper for SDL2 and satellite libraries.\n\n## Synopsis\n\n```cpp\ntry {\n  using namespace SDL2pp;\n\n  // Init SDL; will be automatically deinitialized when the object is destroyed\n  SDL sdl(SDL_INIT_VIDEO | SDL_INIT_AUDIO);\n\n  // Likewise, init SDL_ttf library\n  SDLTTF sdl_ttf;\n\n  // Straightforward wrappers around corresponding SDL2 objects\n  // These take full care of proper object destruction and error checking\n  Window window(\"libSDL2pp demo\",\n                SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,\n                640, 480, SDL_WINDOW_RESIZABLE);\n  Renderer renderer(window, -1, SDL_RENDERER_ACCELERATED);\n  Texture sprite1(renderer, SDL_PIXELFORMAT_ARGB8888,\n                            SDL_TEXTUREACCESS_STATIC, 16, 16);\n  Texture sprite2(renderer, \"sprite.png\"); // SDL_image support\n\n  Font font(\"Vera.ttf\", 20); // SDL_ttf font\n\n  // Initialize audio mixer\n  Mixer mixer(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);\n\n  Chunk sound(\"effect.ogg\"); // OGG sound file\n\n  // Create texture from surface containing text rendered by SDL_ttf\n  Texture text(renderer, font.RenderText_Solid(\"Hello, world!\",\n               SDL_Color{255, 255, 255, 255}));\n\n  unsigned char pixels[16 * 16 * 4];\n\n  // Note proper constructor for Rect\n  sprite1.Update(Rect(0, 0, 16, 16), pixels, 16 * 4);\n\n  // Most setter methods are chainable\n  renderer.SetLogicalSize(640, 480).SetDrawColor(0, 16, 32).Clear();\n\n  // Also note a safe way to specify null rects and points\n  renderer.Copy(sprite1, NullOpt, NullOpt);\n\n  // There are multiple convenient ways to construct e.g. a Rect;\n  // Objects provide extensive set of getters\n  renderer.Copy(text, NullOpt, Rect(Point(0, 0), text.GetSize()));\n\n  // Copy() is overloaded, providing access to both SDL_RenderCopy and SDL_RenderCopyEx\n  renderer.Copy(sprite2, NullOpt, NullOpt, 45.0);\n\n  renderer.Present();\n\n  // Play our sound one time on a first available mixer channel\n  mixer.PlayChannel(-1, sound);\n\n  // You can still access wrapped C SDL types\n  SDL_Renderer* sdl_renderer = renderer.Get();\n\n  // Of course, C SDL2 API is still perfectly valid\n  SDL_Delay(2000);\n\n  // All SDL objects are released at this point or if an error occurs\n} catch (SDL2pp::Exception\u0026 e) {\n  // Exception stores SDL_GetError() result and name of function which failed\n  std::cerr \u003c\u003c \"Error in: \" \u003c\u003c e.GetSDLFunction() \u003c\u003c std::endl;\n  std::cerr \u003c\u003c \"  Reason: \" \u003c\u003c e.GetSDLError() \u003c\u003c std::endl;\n} catch (std::exception\u0026 e) {\n  // This also works (e.g. \"SDL_Init failed: No available video device\")\n  std::cerr \u003c\u003c e.what() \u003c\u003c std::endl;\n}\n```\n\nThere's also more elaborate [tutorial](https://github.com/libSDL2pp/libSDL2pp-tutorial).\n\n## Features\n\nCurrently, the library provides wrapper classes for\n\n* SDL\n  * Library initialization/deinitialization\n  * Audio\n    * Audio device\n    * WAV-related functions\n    * SDL_AudioSpec\n  * Graphics\n    * SDL_Point\n    * SDL_Rect\n    * SDL_Renderer\n    * SDL_Surface\n    * SDL_Texture\n    * SDL_Window\n  * I/O\n    * SDL_RWops\n* SDL_image\n  * Library initialization/deinitialization\n  * Loading functions integrated into Texture and Surface\n* SDL_mixer\n  * Library initialization/deinitialization\n  * Sound sample handling (Mix_Chunk)\n  * Music handling (Mix_Music)\n  * Mixer class which encapsulates device handling and all playback functions\n* SDL_ttf\n  * Library initialization/deinitialization\n  * TTF_Font (all functions covered)\n\neach with a subset of methods corresponding to SDL functions working\nwith specific types of objects and, in some cases, additional convenience\nmethods. These classes support:\n\n* RAII-style initialization and destruction, automatic resource lifetime\n  control (you no longer need to care of manually freeing your stuff)\n* Total error checking: exceptions are thrown if any SDL function fails.\n  Exception itself allows retrieval of SDL error string (you no longer\n  need to manually check return code after each function call)\n* Method overloading, default arguments, method chaining allow shorter\n  and cleaner code\n* Move semantics support, which allow you to store SDL objects\n  in containers and pass/return them by value without noticeable overhead\n\nSet of functional extensions above SDL2 is also available:\n\n* RWops adapters for C++ containers and streams\n* Optional object to safely handle values which may not be present,\n  (for which SDL2 usually uses NULL pointers)\n* Number of additional methods and operator support for Point and Rect\n\n## Building\n\nDependencies:\n* [cmake](https://cmake.org/)\n* [SDL2](https://libsdl.org/)\n* [SDL2_image](https://www.libsdl.org/projects/SDL_image/) (optional)\n* [SDL2_mixer](https://www.libsdl.org/projects/SDL_mixer/) (optional)\n* [SDL2_ttf](https://www.libsdl.org/projects/SDL_ttf/) (optional)\n\nTo build standalone version:\n\n```shell\ncmake .\ncmake --build .\n```\n\nFollowing variables may be supplied to CMake to affect build:\n\n* `SDL2PP_WITH_IMAGE` - enable SDL_image support (default ON)\n* `SDL2PP_WITH_MIXER` - enable SDL_mixer support (default ON)\n* `SDL2PP_WITH_TTF` - enable SDL_ttf support (default ON)\n* `SDL2PP_WITH_EXAMPLES` - enable building example programs (only for standalone build, default ON)\n* `SDL2PP_WITH_TESTS` - enable building tests (only for standalone build, default ON)\n* `SDL2PP_STATIC` - build static library instead of shared (only for standalone build, default OFF)\n* `SDL2PP_ENABLE_LIVE_TESTS` - enable tests which require X11 and/or audio device to run (only for standalone build, default ON)\n\n## Installation\n\nTo install the library system-wide, run:\n\n```shell\ncmake .\ncmake --build .\ncmake --install .\n```\n\nYou can change installation prefix with CMAKE_INSTALL_PREFIX cmake\nvariable:\n\n```shell\ncmake -DCMAKE_INSTALL_PREFIX=/usr/local .\ncmake --build .\ncmake --install .\n```\n\nSDL2pp installs `pkg-config` file, so it can be used with any build\nsystem that interacts with `pkg-config`, including CMake, meson and\nGNU Autotools. It also installs CMake module file, which can be used\nfrom CMake directly:\n\n```cmake\nfind_package(SDL2pp REQUIRED)\n\ntarget_link_libraries(mytarget SDL2pp::SDL2pp)\n```\n\n## Bundling ##\n\nThe library is easy to integrate into other CMake projects\n(and as the library has no stable API yet, this way of using it is\nstill recommended).\n\nJust place the library into dedicated directory in your project\n(for example, extlib/libSDL2pp) and add\n\n```cmake\nset(SDL2PP_WITH_IMAGE ON) # if you need SDL_image support\nset(SDL2PP_WITH_MIXER ON) # if you need SDL_mixer support\nset(SDL2PP_WITH_TTF ON) # if you need SDL_ttf support\nadd_subdirectory(extlib/libSDL2pp)\n```\n\ninto your core CMakeLists.txt. This will act similar to how\n`find_package` usually does, and will provide `SDL2pp::SDL2pp`\ntarget for your project. You will then be able it as usual:\n\n```cmake\ntarget_link_libraries(mytarget SDL2pp::SDL2pp)\n```\n\nIf bundled, libSDL2pp does not build examples and becomes a static\nlibrary. See [hoverboard](https://github.com/AMDmi3/hoverboard-sdl/blob/5729f9fb6929f6e8147481f5b21772fc1e35562a/CMakeLists.txt#L34-L40)\nproject as an example of using both bundled and systemwide SDL2pp.\n\n## Completeness\n\nThe library still doesn't cover all aspects of SDL2, and the development\nis generally guided by the author's needs and interest without a goal\nfor covering all SDL2 functions as soon as possible. However, if\nyou need specific bits which are not yet implemented in the library,\nfeel free to drop an issue. Patches are of course more than welcome.\n\nIt should be noted, however, that I currently do not plan to implement\nany wrappers over non object-oriented SDL2 code, as these will not bring\nany benefits over using plain C API. E.g. I see no point in implementing\nSDL2pp::Delay() as it won't bring any convenience over SDL_Delay().\n\nThe same strongly applies to the SDL2 bits which duplicate C++17\nstandard library, e.g. threads and atomic ops.\n\n## Users\n\nProjects using libSDL2pp:\n\n* [fontbm](https://github.com/vladimirgamalian/fontbm) - Command line font generator, compatible with BMFont\n* [hoverboard-sdl](https://github.com/AMDmi3/hoverboard-sdl) - Desktop version of xkcd 1608 \"Hoverboard\" game\n* [neopedersia](https://github.com/vladimirgamalian/neopedersia) - Nexus Wars style game\n* [OpenDaed](https://github.com/AMDmi3/opendaed) - Libre reimplementation of The Daedalus Encounter game\n* [OpenStrike](https://github.com/AMDmi3/openstrike) - Libre reimplementation of Jungle and Desert Strike games\n* [osmview](https://bitbucket.org/ipopov/osmview) - Desktop OpenStreetMap viewer\n* [planetonomy](https://github.com/AMDmi3/planetonomy) - Old-school platformer/exploration game with CGA graphics\n\n## WWW\n\n* [GitHub page](https://github.com/libSDL2pp/libSDL2pp)\n* [Online documentation](https://sdl2pp.amdmi3.ru/)\n\n## Author\n\n* [Dmitry Marakasov](https://github.com/AMDmi3) \u003camdmi3@amdmi3.ru\u003e\n\n## Contributors\n\n* [Aargonian](https://github.com/Aargonian)\n* [Carl Schwope](https://github.com/Lowest0ne)\n* [Carsten Elton Sorensen](https://github.com/csoren)\n* [Ilya Popov](https://github.com/ilyapopov)\n* [kumar8600](https://github.com/kumar8600)\n* [ooxi](https://github.com/ooxi)\n* [Vladimir Gamalian](https://github.com/vladimirgamalian)\n* [Vraiment](https://github.com/Vraiment)\n\n## License\n\nlibSDL2pp comes under zlib license, the same license as SDL2. See COPYING.txt.\n","funding_links":[],"categories":["TODO scan for Android support in followings","C/C++","IOS","Frameworks/Engines/Libraries","Graphics"],"sub_categories":["Multimedia","iOS"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlibSDL2pp%2FlibSDL2pp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FlibSDL2pp%2FlibSDL2pp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlibSDL2pp%2FlibSDL2pp/lists"}