mirror of
https://github.com/allankoechke/raylib-cpp.git
synced 2026-11-30 17:19:27 +00:00
885448b0507efe68b18b663fa12d6c2bd0026443
raylib-cpp
C++ wrapper library around raylib, a simple and easy-to-use library to enjoy videogames programming.
Provides object-oriented wrappers around the struct interfaces.
Example
#include "raylib/raylib.hpp"
int main()
{
int screenWidth = 800;
int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib-cpp - basic window");
raylib::Texture logo("raylib_logo.png");
SetTargetFPS(60);
while (!w.ShouldClose())
{
BeginDrawing();
raylib::Color::RayWhite.ClearBackground();
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
// Object methods.
logo.Draw(screenWidth / 2 - texture.getWidth() / 2, screenHeight / 2 - texture.getHeight() / 2);
EndDrawing();
}
// UnloadTexture() and CloseWindow() are called automatically.
return 0;
}
Convention
There are a few conventions that raylib-cpp takes on when adopting raylib...
Constructors
Object constructors load raylib objects.
// raylib
Texture2D texture = LoadTexture("texture.png");
// raylib-cpp
raylib::Texture2D texture("texture.png");
Method Names
If a method contains an object name, it is removed from its name in the class definition.
// raylib
DrawTexture(texture, 50, 50, RAYWHITE);
// raylib-cpp
texture.Draw(50, 50, RAYWHITE);
Object Destructors
Objects will attempt to unload their respective raylib resources on destruction. This means no need to call Unload or Close methods.
// raylib
InitWindow(640, 480, "Hello World");
CloseWindow();
// raylib-cpp
raylib::Window w(640, 480, "Hello World");
// CloseWindow(); // w.Close() is automatically called when the object is destructed.
Object Methods
When a raylib method has an object as one of its arguments, it becomes part of the class definition.
// raylib
Vector2 position(50, 50);
DrawPixelV(position, PURPLE);
// raylib-cpp
raylib::Vector2 position(50, 50);
position.DrawPixel(raylib::Color::Purple);
// ... or
raylib::Color::Purple.DrawPixel(position);
Protery Get/Set
Properties can be assigned through getter and setter methods. You still have access to the internal properties, however.
// raylib
Vector2 position;
position.x = 50;
position.y = 100;
// raylib-cpp
raylib::Vector2 position;
position.setX(50);
position.setY(100);
Development
mkdir build
cd build
cmake ..
make
make test
./examples/core_basic_window
Languages
C++
83.9%
C
7.4%
Makefile
6.1%
CMake
2.6%