๐Ÿ“ฆ RobLoach / raylib-cpp

C++ Object Oriented Wrapper for raylib

โ˜… 861 stars โ‘‚ 108 forks ๐Ÿ‘ 861 watching โš–๏ธ zlib License
raylib
๐Ÿ“ฅ Clone https://github.com/RobLoach/raylib-cpp.git
HTTPS git clone https://github.com/RobLoach/raylib-cpp.git
SSH git clone git@github.com:RobLoach/raylib-cpp.git
CLI gh repo clone RobLoach/raylib-cpp
Rob Loach Rob Loach Merge pull request #373 from und3f/add-vec-add-sub-float-operations 21b0d0f 2 months ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ examples
๐Ÿ“ include
๐Ÿ“ modules
๐Ÿ“ projects
๐Ÿ“ tests
๐Ÿ“„ .clang-format
๐Ÿ“„ .clang-tidy
๐Ÿ“„ .cmake-format.yaml
๐Ÿ“„ .editorconfig
๐Ÿ“„ .gitignore
๐Ÿ“„ .gitmodules
๐Ÿ“„ clib.json
๐Ÿ“„ CMakeLists.txt
๐Ÿ“„ CPPLINT.cfg
๐Ÿ“„ LICENSE
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ README.md
raylib-cpp Logo

raylib-cpp Targeting raylib 5.0 Tests License

raylib-cpp is a C++ wrapper library for raylib, 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.

Example

`` cpp #include "raylib-cpp.hpp" int main() { int screenWidth = 800; int screenHeight = 450; raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); raylib::Texture logo("raylib_logo.png"); SetTargetFPS(60); while (!window.ShouldClose()) { BeginDrawing(); window.ClearBackground(RAYWHITE); DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); // Object methods. logo.Draw( screenWidth / 2 - logo.GetWidth() / 2, screenHeight / 2 - logo.GetHeight() / 2); EndDrawing(); } // UnloadTexture() and CloseWindow() are called automatically. return 0; } %%CODEBLOCK0%% cpp // raylib Texture2D texture = LoadTexture("texture.png"); // raylib-cpp raylib::Texture2D texture("texture.png"); %%CODEBLOCK1%% cpp // raylib Vector2 position(50, 50); DrawPixelV(position, PURPLE); // raylib-cpp raylib::Vector2 position(50, 50); position.DrawPixel(PURPLE); %%CODEBLOCK2%% cpp // raylib DrawTexture(texture, 50, 50, WHITE); // raylib-cpp texture.Draw(50, 50, WHITE); %%CODEBLOCK3%% cpp // raylib DrawTexture(texture, 50, 50, WHITE); // raylib-cpp texture.Draw(50, 50); // WHITE is provided as the default tint. %%CODEBLOCK4%% cpp // raylib InitWindow(640, 480, "Hello World"); CloseWindow(); // raylib-cpp raylib::Window window(640, 480, "Hello World"); // window.Close() will be called automatically when the object is destructed. %%CODEBLOCK5%% cpp // raylib Vector2 position; position.x = 50; position.y = 100; // raylib-cpp raylib::Vector2 position; position.SetX(50); position.SetY(100); // ... or position.x = 50; position.y = 100; %%CODEBLOCK6%% cpp // raylib Color color = GRAY; DrawPixel(50, 50, color); Vector2 position = {50.0f, 50.0f}; DrawPixelV(position, color); // Extra V in method name. // raylib-cpp raylib::Color color = raylib::Color::Gray(); color.DrawPixel(50, 50); Vector2 position(50.0f, 50.0f); color.DrawPixel(position); // No V in method name. position.DrawPixel(color); // Alternatively %%CODEBLOCK7%% cpp // raylib Image cat = ImageLoad("cat.png"); ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 }); ImageFlipHorizontal(&cat); ImageResize(&cat, 150, 200); // raylib-cpp raylib::Image cat("cat.png"); cat.Crop(100, 10, 280, 380) .FlipHorizontal() .Resize(150, 200); %%CODEBLOCK8%% cpp // raylib Vector2 position = {50, 50}; Vector2 speed = {10, 10}; position.x += speed.x; position.y += speed.y; // raylib-cpp raylib::Vector2 position(50, 50); raylib::Vector2 speed(10, 10); position += speed; // Addition assignment operator override. %%CODEBLOCK9%% cpp // raylib FilePathList files = LoadDirectoryFiles("."); TraceLog(LOG_INFO, "Count: %i", files.count); for (int i = 0; i < files.count; i++) { TraceLog(LOG_INFO, "File: %s", files.paths[i]); } UnloadDirectoryFiles(files); // raylib-cpp std::vector<std::string> files = raylib::GetDirectoryFiles("."); TraceLog(LOG_INFO, "Count: %i", files.size()); for (auto& file : files) { TraceLog(LOG_INFO, "File: %s", file.c_str()); } %%CODEBLOCK10%% cpp // raylib const char* url = "https://raylib.com"; OpenURL(url); // raylib-cpp std::string url = "https://raylib.com"; raylib::OpenURL(url); %%CODEBLOCK11%% cpp // raylib Texture texture = LoadTexture("FileNotFound.png"); if (texture.width == 0) { TraceLog(LOG_ERROR, "Texture failed to load!"); } // raylib-cpp try { raylib::Texture texture("FileNotFound.png"); } catch (raylib::RaylibException& error) { TraceLog(LOG_ERROR, "Texture failed to load!"); } %%CODEBLOCK12%% cpp // raylib Vector2 direction = {50, 50}; Vector2 newDirection = Vector2Rotate(direction, 30); // raylib-cpp raylib::Vector2 direction(50, 50); raylib::Vector2 newDirection = direction.Rotate(30); %%CODEBLOCK13%%cpp import raylib; using raylib::Texture; using raylib::Window; int main() { int screenWidth = 800; int screenHeight = 450; Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); Texture logo("raylib_logo.png"); // ... } %%CODEBLOCK14%% cpp #include "path/to/raylib-cpp.hpp" %%CODEBLOCK15%% bash git clone https://github.com/RobLoach/raylib-cpp.git cd raylib-cpp mkdir build cd build cmake .. make make test ./examples/core_basic_window %%CODEBLOCK16%% mkdir build cd build emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3" emmake make %%CODEBLOCK17%% git submodule update --init doxygen projects/Doxygen/Doxyfile %%CODEBLOCK18%% npm run deploy %%CODEBLOCK19%% cpplint --recursive include ` ### Defines - RAYLIBCPPNO_MATH - When set, will skip adding the raymath.h` integrations

License

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 for further details.