{"id":13731237,"url":"https://github.com/RobLoach/raylib-cpp","last_synced_at":"2025-05-08T04:32:19.991Z","repository":{"id":37238897,"uuid":"165996488","full_name":"RobLoach/raylib-cpp","owner":"RobLoach","description":"C++ Object Oriented Wrapper for raylib","archived":false,"fork":false,"pushed_at":"2024-05-04T19:43:51.000Z","size":12631,"stargazers_count":553,"open_issues_count":21,"forks_count":75,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-04T20:32:13.167Z","etag":null,"topics":["raylib"],"latest_commit_sha":null,"homepage":"https://robloach.github.io/raylib-cpp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobLoach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2019-01-16T07:41:50.000Z","updated_at":"2024-06-27T20:40:12.050Z","dependencies_parsed_at":"2023-02-12T13:00:37.057Z","dependency_job_id":"65889dbf-b2cf-4684-b423-c0d67298f447","html_url":"https://github.com/RobLoach/raylib-cpp","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2Fraylib-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2Fraylib-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2Fraylib-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2Fraylib-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobLoach","download_url":"https://codeload.github.com/RobLoach/raylib-cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224702180,"owners_count":17355510,"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":["raylib"],"created_at":"2024-08-03T02:01:25.777Z","updated_at":"2024-11-14T22:30:32.214Z","avatar_url":"https://github.com/RobLoach.png","language":"C++","readme":"![raylib-cpp Logo](projects/Doxygen/raylib-cpp_256x256.png)\n\n# raylib-cpp ![Targeting raylib 5.0](https://img.shields.io/badge/for_raylib-5.0-blue) [![Tests](https://github.com/RobLoach/raylib-cpp/workflows/Tests/badge.svg)](https://github.com/RobLoach/raylib-cpp/actions?query=workflow%3ATests+branch%3Amaster) [![License](https://img.shields.io/badge/license-zlib%2Flibpng-blue.svg)](LICENSE)\n\n[raylib-cpp](https://github.com/robloach/raylib-cpp) is a C++ wrapper library for [raylib](https://www.raylib.com), a simple and easy-to-use library to enjoy videogames programming. This C++ header provides object-oriented wrappers around *raylib*'s struct interfaces. *raylib-cpp* is not required to use *raylib* in C++, but the classes do bring using the raylib API more inline with C++'s language paradigm.\n\n## Example\n\n``` cpp\n#include \"raylib-cpp.hpp\"\n\nint main() {\n    int screenWidth = 800;\n    int screenHeight = 450;\n\n    raylib::Window window(screenWidth, screenHeight, \"raylib-cpp - basic window\");\n    raylib::Texture logo(\"raylib_logo.png\");\n\n    SetTargetFPS(60);\n\n    while (!window.ShouldClose())\n    {\n        BeginDrawing();\n\n        window.ClearBackground(RAYWHITE);\n\n        DrawText(\"Congrats! You created your first window!\", 190, 200, 20, LIGHTGRAY);\n\n        // Object methods.\n        logo.Draw(\n            screenWidth / 2 - logo.GetWidth() / 2,\n            screenHeight / 2 - logo.GetHeight() / 2);\n\n        EndDrawing();\n    }\n\n    // UnloadTexture() and CloseWindow() are called automatically.\n\n    return 0;\n}\n```\n\nSee the [examples folder](examples) for more of the raylib examples that have been ported over to *raylib-cpp*.\n\n## Features\n\nThere are a few conventions that raylib-cpp takes on when adopting raylib. See the [raylib-cpp documentation](https://robloach.github.io/raylib-cpp/index.html) for details on the entire API.\n\n### Constructors\n\nObject constructors load raylib objects.\n\n``` cpp\n// raylib\nTexture2D texture = LoadTexture(\"texture.png\");\n\n// raylib-cpp\nraylib::Texture2D texture(\"texture.png\");\n```\n\n### Object Methods\n\nWhen a raylib method has an object as one of its arguments, you can call the method on the object itself.\n\n``` cpp\n// raylib\nVector2 position(50, 50);\nDrawPixelV(position, PURPLE);\n\n// raylib-cpp\nraylib::Vector2 position(50, 50);\nposition.DrawPixel(PURPLE);\n```\n\n### Method Names\n\nIf a method's name contains an object's name, it is removed from its name to shorten the method name.\n\n``` cpp\n// raylib\nDrawTexture(texture, 50, 50, WHITE);\n\n// raylib-cpp\ntexture.Draw(50, 50, WHITE);\n```\n\n### Optional Parameters\n\nMany methods have optional parameters with sane defaults.\n\n``` cpp\n// raylib\nDrawTexture(texture, 50, 50, WHITE);\n\n// raylib-cpp\ntexture.Draw(50, 50); // WHITE is provided as the default tint.\n```\n\n### Object Destructors\n\nObjects will attempt to unload their respective raylib resources on destruction. This means that there is no need to call Unload or Close methods. This applies to the window, textures, images, sounds, etc.\n\n``` cpp\n// raylib\nInitWindow(640, 480, \"Hello World\");\nCloseWindow();\n\n// raylib-cpp\nraylib::Window window(640, 480, \"Hello World\");\n// window.Close() will be called automatically when the object is destructed.\n```\n\n### Property Get/Set\n\nProperties can be assigned through getter and setter methods. However, you still have access to the internal properties.\n\n``` cpp\n// raylib\nVector2 position;\nposition.x = 50;\nposition.y = 100;\n\n// raylib-cpp\nraylib::Vector2 position;\nposition.SetX(50);\nposition.SetY(100);\n\n// ... or\nposition.x = 50;\nposition.y = 100;\n```\n\n### Function Overloading\n\nMany similar raylib method names have different name suffixes based on what arguments they take. With raylib-cpp, these cases use [function overloading](https://en.wikipedia.org/wiki/Function_overloading) to allow using the same method names.\n\n``` cpp\n// raylib\nColor color = GRAY;\nDrawPixel(50, 50, color);\nVector2 position = {50.0f, 50.0f};\nDrawPixelV(position, color); // Extra V in method name.\n\n// raylib-cpp\nraylib::Color color = raylib::Color::Gray();\ncolor.DrawPixel(50, 50);\nVector2 position(50.0f, 50.0f);\ncolor.DrawPixel(position); // No V in method name.\nposition.DrawPixel(color); // Alternatively\n```\n\n### Method Chaining\n\nWhen there's a method that doesn't return anything, in most cases it'll return the object itself, allowing [method chaining](https://en.wikipedia.org/wiki/Method_chaining).\n\n``` cpp\n// raylib\nImage cat = ImageLoad(\"cat.png\");\nImageCrop(\u0026cat, (Rectangle){ 100, 10, 280, 380 });\nImageFlipHorizontal(\u0026cat);\nImageResize(\u0026cat, 150, 200);\n\n// raylib-cpp\nraylib::Image cat(\"cat.png\");\ncat.Crop(100, 10, 280, 380)\n   .FlipHorizontal()\n   .Resize(150, 200);\n```\n\n### Operators\n\nThere are [operator overloads](https://en.wikipedia.org/wiki/Operator_overloading) implemented for objects.\n\n``` cpp\n// raylib\nVector2 position = {50, 50};\nVector2 speed = {10, 10};\nposition.x += speed.x;\nposition.y += speed.y;\n\n// raylib-cpp\nraylib::Vector2 position(50, 50);\nraylib::Vector2 speed(10, 10);\nposition += speed; // Addition assignment operator override.\n```\n\n### Vector-Based Returns\n\nWhen there is a function that would return a pointer-array, there is a wrapper that allows returning a [vector](https://www.cplusplus.com/reference/vector/vector/) of objects instead.\n\n``` cpp\n// raylib\nFilePathList files = LoadDirectoryFiles(\".\");\nTraceLog(LOG_INFO, \"Count: %i\", files.count);\nfor (int i = 0; i \u003c files.count; i++) {\n    TraceLog(LOG_INFO, \"File: %s\", files.paths[i]);\n}\nUnloadDirectoryFiles(files);\n\n// raylib-cpp\nstd::vector\u003cstd::string\u003e files = raylib::GetDirectoryFiles(\".\");\nTraceLog(LOG_INFO, \"Count: %i\", files.size());\nfor (auto\u0026 file : files) {\n    TraceLog(LOG_INFO, \"File: %s\", file.c_str());\n}\n```\n\n### String Functions\n\nMany of the raylib functions have `std::string`-related overrides to allow calling them directly with `std::string`s and avoid having to use the `.c_str()` method.\n\n``` cpp\n// raylib\nconst char* url = \"https://raylib.com\";\nOpenURL(url);\n\n// raylib-cpp\nstd::string url = \"https://raylib.com\";\nraylib::OpenURL(url);\n```\n\n### Exceptions\n\nWhen loading an asset fails, raylib will log a warning, but provide no other feedback for you to act upon. raylib-cpp will throw a [`RaylibException`](include/RaylibException.hpp) [runtime exception](https://en.cppreference.com/w/cpp/error/runtime_error), allowing to provide a safe method for catching failed loads.\n\n``` cpp\n// raylib\nTexture texture = LoadTexture(\"FileNotFound.png\");\nif (texture.width == 0) {\n    TraceLog(LOG_ERROR, \"Texture failed to load!\");\n}\n\n// raylib-cpp\ntry {\n    raylib::Texture texture(\"FileNotFound.png\");\n}\ncatch (raylib::RaylibException\u0026 error) {\n    TraceLog(LOG_ERROR, \"Texture failed to load!\");\n}\n```\n\n### RayMath\n\nThe [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) methods are included.\n\n``` cpp\n// raylib\nVector2 direction = {50, 50};\nVector2 newDirection = Vector2Rotate(direction, 30);\n\n// raylib-cpp\nraylib::Vector2 direction(50, 50);\nraylib::Vector2 newDirection = direction.Rotate(30);\n```\n\n## Getting Started\n\n*raylib-cpp* is a header-only library. This means in order to use it, you must link your project to [raylib](https://www.raylib.com/), and then include [`raylib-cpp.hpp`](raylib-cpp/include/raylib-cpp.hpp).\n\n1. Set up a *raylib* project using the [build and install instructions](https://github.com/raysan5/raylib#build-and-installation)\n2. Ensure `.cpp` files are compiled with C++\n3. Download *raylib-cpp*\n4. Include [`include/raylib-cpp.hpp`](include/raylib-cpp.hpp)\n    ``` cpp\n    #include \"path/to/raylib-cpp.hpp\"\n    ```\n\n### Starter Projects\n\nThe [projects directory](projects) includes some starter templates...\n\n- [CMake template](projects/CMake)\n- [Make template](projects/Make)\n- [VSCode template](projects/VSCode)\n\nIf there's a project template you would like to see added, feel free to [make an issue](https://github.com/RobLoach/raylib-cpp/issues) and we can add it in.\n\n### Applications\n\n- [Ian Pan's Raylib Games](https://github.com/ianpan870102/raylib-practices)\n\n## Development\n\nThe following are some tools in order to build and contribute to *raylib-cpp*...\n\n### Compiling\n\nSince *raylib-cpp* is a header only library, the build process is the same as raylib's, except you will use C++ to compile instead of C. The following are some specific instructions on local development.\n\n#### Desktop\n\n*raylib-cpp* uses [CMake](https://cmake.org) as a primary target for development. To build it, and run the tests or examples, use...\n\n``` bash\ngit clone https://github.com/RobLoach/raylib-cpp.git\ncd raylib-cpp\nmkdir build\ncd build\ncmake ..\nmake\nmake test\n./examples/core_basic_window\n```\n\n#### Web\n\nUse [emscripten](https://emscripten.org/) to build and test [core_basic_window_web.cpp](examples/core/core_basic_window_web.cpp).\n\n```\nmkdir build\ncd build\nemcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS=\"-s USE_GLFW=3\"\nemmake make\n```\n\nSee [`core_basic_window_web.html`](examples/core/resources/core_basic_window_web.html) for an example HTML canvas you can you.\n\n### Documentation\n\nTo build the document with [Doxygen](http://www.doxygen.nl/), use...\n\n```\ngit submodule update --init\ndoxygen projects/Doxygen/Doxyfile\n```\n\nTo publish the documentation to GitHub Pages, use...\n\n```\nnpm run deploy\n```\n\n### Coding Standards\n\nThis uses cpplint to adopt coding standards.\n\n```\ncpplint --recursive include\n```\n\n### Defines\n\n- `RAYLIB_CPP_NO_MATH` - When set, will skip adding the `raymath.h` integrations\n\n## License\n\n*raylib-cpp* is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.\n","funding_links":[],"categories":["Engines"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobLoach%2Fraylib-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobLoach%2Fraylib-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobLoach%2Fraylib-cpp/lists"}