{"id":27784531,"url":"https://github.com/dkosmari/sdl2xx","last_synced_at":"2025-04-30T14:28:29.099Z","repository":{"id":289006440,"uuid":"969813870","full_name":"dkosmari/sdl2xx","owner":"dkosmari","description":"A C++23 wrapper for SDL2.","archived":false,"fork":false,"pushed_at":"2025-04-29T05:32:29.000Z","size":486,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T14:28:27.371Z","etag":null,"topics":["cpp","cpp23","sdl","sdl2","zlib-license"],"latest_commit_sha":null,"homepage":"","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/dkosmari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-21T01:18:28.000Z","updated_at":"2025-04-29T05:32:33.000Z","dependencies_parsed_at":"2025-04-21T13:00:38.626Z","dependency_job_id":"103f5678-4bb3-4613-8b6a-4fe5e40efad3","html_url":"https://github.com/dkosmari/sdl2xx","commit_stats":null,"previous_names":["dkosmari/sdl2xx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkosmari%2Fsdl2xx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkosmari%2Fsdl2xx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkosmari%2Fsdl2xx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkosmari%2Fsdl2xx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dkosmari","download_url":"https://codeload.github.com/dkosmari/sdl2xx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251721183,"owners_count":21632777,"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":["cpp","cpp23","sdl","sdl2","zlib-license"],"created_at":"2025-04-30T14:28:26.316Z","updated_at":"2025-04-30T14:28:29.089Z","avatar_url":"https://github.com/dkosmari.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SDL2XX - A modern C++ wrapper for SDL2\n\nSDL2XX is a modern C++ wrapper for SDL2. Currently the target is C++23.\n\nIt's licensed under the Zlib license (same as SDL2).\n\n\u003e Note: this is still a work in progress.\n\n\u003e Documentation is still missing, but the C++ API maps naturally to the C API.\n\n\n## Simple Example\n\n```cpp\n#include \u003cexception\u003e\n#include \u003ciostream\u003e\n\n#include \u003csdl2xx/sdl.hpp\u003e\n\nusing sdl::vec2;\nusing namespace sdl::literals;\n\nint main(int, char* [])\n{\n    try {\n        sdl::init guard{sdl::init::flag::video};\n\n        sdl::window win{\"Simple App\",\n                        sdl::window::pos_centered,\n                        {1280, 720},\n                        0};\n\n        sdl::renderer rend{win,\n                           -1,\n                           sdl::renderer::flag::accelerated | sdl::renderer::flag::present_vsync};\n\n        auto box = sdl::rect::from_corners({300, 200},\n                                           win.get_size() - vec2{300, 200});\n\n        bool running = true;\n\n        while (running) {\n\n            // Clear window to a navy blue background.\n            rend.set_color(0x000080_rgb);\n            rend.clear();\n\n            // Draw yellow box.\n            rend.set_color(sdl::color::yellow);\n            rend.fill_box(box);\n\n            rend.present();\n\n            // Process events.\n            while (auto event = sdl::events::poll()) {\n                switch (event-\u003etype) {\n\n                    case SDL_QUIT:\n                        running = false;\n                        break;\n\n                }\n            }\n        }\n    }\n    catch (std::exception\u0026 e) {\n        std::cout \u003c\u003c \"Error: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n        return -1;\n    }\n}\n```\n\nSee the [examples directory](examples) for more examples of the API usage.\n\n\n## Key features\n\n- Convenient short namespaces:\n\n  - `sdl` for the top-level namespace.\n  - `sdl::img` for `SDL_image`.\n  - `sdl::ttf` for `SDL_ttf`.\n  - `sdl::mix` for `SDL_mixer`.\n\n- Entities that are opaque pointers are handled through movable RAII classes. For\n  instance:\n  \n  - `SDL_Window*` → `sdl::window`\n  - `SDL_Renderer*` → `sdl::renderer`\n  - `SDL_Surface*` → `sdl::surface`\n  - `SDL_Texture*` → `sdl::texture`\n  \n  Objects can be in an \"invalid\" state, where they just store a null pointer. In such a\n  state, you can only construct, destroy or check for validity:\n  \n  ```cpp\n  sdl::window win{/* ... */};\n  // ...\n  if (/* ... */)\n      win.destroy(); // if this executes, win is now invalid\n  // ...\n  \n  if (win)\n      win.minimize();\n\n  if (win.is_valid())\n      win.maximize();\n  \n  if (win.data())\n      use_raw_pointer(win.data());\n  ```\n\n- Lifetime guard types:\n\n  - `sdl::init`: calls `SDL_Init()` and `SDL_Quit()`.\n  - `sdl::img::init`: calls `IMG_Init()` and `IMG_Quit()`.\n  - `sdl::ttf::init`: calls `TTF_Init()` and `TTF_Quit()`.\n\n- Various utility types are extended, with extra methods and operators:\n\n  - `SDL_Point` → `sdl::vec2` (or `sdl::point`)\n  - `SDL_FPoint` → `sdl::vec2f` (or `sdl::pointf`)\n  - `SDL_Rect` → `sdl::rect`\n  - `SDL_FRect` → `sdl::rectf`\n  - `SDL_Color` → `sdl::color`\n\n- Additional types:\n\n  - `sdl::degrees`, `sdl::degreesf`: represent angles in degrees.\n  - `sdl::radians`, `sdl::radiansf`: represent angles in radians.\n  - `sdl::unique_ptr\u003c\u003e`: uses `SDL_malloc()` and `SDL_free()` to manage memory allocations.\n  - `sdl::blob`: represents raw byte blobs.\n\n- Literals, found in `sdl::literals`:\n\n  - `_deg` → `sdl::degrees`\n  - `_degf` → `sdl::degreesf`\n  - `_rad` → `sdl::radians`\n  - `_radf` → `sdl::radiansf`\n  - `_rgb` → `sdl::color` (with `.a = 0xff`)\n  - `_rgba` → `sdl::color`\n  \n- Functions either throw `sdl::error` or return `std::expected\u003c..., sdl::error\u003e`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkosmari%2Fsdl2xx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdkosmari%2Fsdl2xx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkosmari%2Fsdl2xx/lists"}