Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project (raylib_cpp
VERSION 5.0.2
VERSION 5.5.0
DESCRIPTION "raylib-cpp C++ Object Oriented Wrapper for raylib"
HOMEPAGE_URL "https://github.com/robloach/raylib-cpp"
LANGUAGES C CXX
Expand Down Expand Up @@ -41,4 +41,4 @@ if(BUILD_RAYLIB_CPP_EXAMPLES)
${CMAKE_CURRENT_SOURCE_DIR}/tests/raylib_cpp_test.cpp
)
endif()
endif()
endif()
2 changes: 1 addition & 1 deletion clib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raylib-cpp",
"version": "5.0.1",
"version": "5.5.0",
"repo": "RobLoach/raylib-cpp",
"description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib",
"homepage": "https://github.com/robloach/raylib-cpp",
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (NOT raylib_FOUND)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG ae50bfa2cc569c0f8d5bc4315d39db64005b1b08
GIT_TAG 5.5
GIT_SHALLOW 1
)
FetchContent_GetProperties(raylib)
Expand Down
6 changes: 3 additions & 3 deletions include/AudioStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AudioStream : public ::AudioStream {
* Unload audio stream and free memory
*/
void Unload() {
if (IsReady()) {
if (IsValid()) {
::UnloadAudioStream(*this);
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ class AudioStream : public ::AudioStream {
/**
* Retrieve whether or not the audio stream is ready.
*/
bool IsReady() const { return ::IsAudioStreamReady(*this); }
bool IsValid() const { return ::IsAudioStreamValid(*this); }

/**
* Load audio stream (to stream raw audio pcm data)
Expand All @@ -192,7 +192,7 @@ class AudioStream : public ::AudioStream {
void Load(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) {
Unload();
set(::LoadAudioStream(SampleRate, SampleSize, Channels));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load audio stream");
}
}
Expand Down
6 changes: 3 additions & 3 deletions include/AutomationEventList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AutomationEventList : public ::AutomationEventList {
void Load(const char* fileName) {
Unload();
set(::LoadAutomationEventList(fileName));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load automation event list");
}
}
Expand All @@ -80,7 +80,7 @@ class AutomationEventList : public ::AutomationEventList {
* Update audio stream buffers with data
*/
void Unload() {
if (!IsReady()) {
if (!IsValid()) {
return;
}

Expand All @@ -96,7 +96,7 @@ class AutomationEventList : public ::AutomationEventList {
#endif
}

bool IsReady() { return events != nullptr; }
bool IsValid() { return events != nullptr; }

bool Export(const char* fileName) { return ::ExportAutomationEventList(*this, fileName); }

Expand Down
7 changes: 7 additions & 0 deletions include/Camera3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class Camera3D : public ::Camera3D {
*/
Vector2 GetWorldToScreen(::Vector3 position) const { return ::GetWorldToScreen(position, *this); }

/**
* Get a ray trace from screen position (i.e mouse) in a viewport
*/
Ray GetScreenToWorldRay(::Vector2 position, int width, int height) {
return ::GetScreenToWorldRayEx(position, *this, width, height);
}

/**
* Draw a billboard texture.
*/
Expand Down
11 changes: 11 additions & 0 deletions include/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ class Color : public ::Color {

void DrawRectangleLines(::Rectangle rec, float lineThick) const { ::DrawRectangleLinesEx(rec, lineThick, *this); }

bool IsEqual(::Color color) {
return ::ColorIsEqual(*this, color);
}

bool operator==(const ::Color& other) const { return ::ColorIsEqual(*this, other); }
bool operator!=(const ::Color& other) const { return !::ColorIsEqual(*this, other); }

/**
* Get color multiplied with another color
*/
Expand All @@ -201,6 +208,10 @@ class Color : public ::Color {
*/
Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }

Color Lerp(::Color color2, float factor) {
return ::ColorLerp(*this, color2, factor);
}

/**
* Returns src alpha-blended into dst color with tint
*/
Expand Down
10 changes: 5 additions & 5 deletions include/Font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Font : public ::Font {
*/
void Load(const std::string& fileName) {
set(::LoadFont(fileName.c_str()));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Font with from file: " + fileName);
}
}
Expand All @@ -175,14 +175,14 @@ class Font : public ::Font {
*/
void Load(const std::string& fileName, int fontSize, int* fontChars, int charCount) {
set(::LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Font with from file with font size: " + fileName);
}
}

void Load(const ::Image& image, ::Color key, int firstChar) {
set(::LoadFontFromImage(image, key, firstChar));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Font with from image");
}
}
Expand All @@ -195,15 +195,15 @@ class Font : public ::Font {
int* fontChars,
int charsCount) {
set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars, charsCount));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Font " + fileType + " with from file data");
}
}

/**
* Returns if the font is ready to be used.
*/
bool IsReady() const { return ::IsFontReady(*this); }
bool IsValid() const { return ::IsFontValid(*this); }

/**
* Draw text using font and additional parameters.
Expand Down
7 changes: 7 additions & 0 deletions include/Gamepad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ class Gamepad {
float GetAxisMovement(int axis) const { return ::GetGamepadAxisMovement(number, axis); }

int SetMappings(const std::string& mappings) { return SetGamepadMappings(mappings.c_str()); }

/**
* Set gamepad vibration for both motors (duration in seconds)
*/
void SetVibration(float leftMotor, float rightMotor, float duration) {
::SetGamepadVibration(number, leftMotor, rightMotor, duration);
}
protected:
void set(int gamepadNumber) { number = gamepadNumber; }
};
Expand Down
38 changes: 32 additions & 6 deletions include/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class Image : public ::Image {
*/
static ::Image Cellular(int width, int height, int tileSize) { return ::GenImageCellular(width, height, tileSize); }

/**
* Get clipboard image content.
*/
static ::Image GetClipboard() { return ::GetClipboardImage(); }

~Image() { Unload(); }

Image& operator=(const ::Image& image) {
Expand Down Expand Up @@ -208,7 +213,7 @@ class Image : public ::Image {
*/
void Load(const std::string& fileName) {
set(::LoadImage(fileName.c_str()));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
Expand All @@ -222,7 +227,7 @@ class Image : public ::Image {
*/
void Load(const std::string& fileName, int width, int height, int format, int headerSize) {
set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
Expand All @@ -236,7 +241,7 @@ class Image : public ::Image {
*/
void Load(const std::string& fileName, int* frames) {
set(::LoadImageAnim(fileName.c_str(), frames));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
Expand All @@ -250,7 +255,7 @@ class Image : public ::Image {
*/
void Load(const std::string& fileType, const unsigned char* fileData, int dataSize) {
set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Image data with file type: " + fileType);
}
}
Expand All @@ -264,7 +269,7 @@ class Image : public ::Image {
*/
void Load(const ::Texture2D& texture) {
set(::LoadImageFromTexture(texture));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Image from texture.");
}
}
Expand Down Expand Up @@ -605,6 +610,13 @@ class Image : public ::Image {
::ImageDrawLineV(this, start, end, color);
}

/**
* Description: Draw a line defining thickness within an image
*/
void DrawLine(::Vector2 start, ::Vector2 end, int thick, ::Color color = {255, 255, 255, 255}) {
ImageDrawLineEx(this, start, end, thick, color);
}

void DrawCircle(int centerX, int centerY, int radius, ::Color color = {255, 255, 255, 255}) {
::ImageDrawCircle(this, centerX, centerY, radius, color);
}
Expand All @@ -629,6 +641,8 @@ class Image : public ::Image {
::ImageDrawRectangleLines(this, rec, thick, color);
}

// TODO: Add ImageDrawTriangle()

void Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = {255, 255, 255, 255}) {
::ImageDraw(this, src, srcRec, dstRec, tint);
}
Expand Down Expand Up @@ -728,7 +742,19 @@ class Image : public ::Image {
*
* @return True or false depending on whether the Image has been loaded.
*/
bool IsReady() const { return ::IsImageReady(*this); }
bool IsValid() const { return ::IsImageValid(*this); }

/**
* Create an image from a selected channel of another image (GRAYSCALE)
*/
::Image Channel(int selectedChannel) { return ::ImageFromChannel(*this, selectedChannel); }

/**
* Apply custom square convolution kernel to image
*/
void KernelConvolution(const float* kernel, int kernelSize) {
::ImageKernelConvolution(this, kernel, kernelSize);
}
protected:
void set(const ::Image& image) {
data = image.data;
Expand Down
2 changes: 1 addition & 1 deletion include/Material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Material : public ::Material {
/**
* Check if material is ready
*/
bool IsReady() const { return ::IsMaterialReady(*this); }
bool IsValid() const { return ::IsMaterialValid(*this); }
protected:
void set(const ::Material& material) {
shader = material.shader;
Expand Down
17 changes: 17 additions & 0 deletions include/MeshUnmanaged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ class MeshUnmanaged : public ::Mesh {
}
}

/**
* Export mesh as code file (.h) defining multiple arrays of vertex attributes
*
* @throws raylib::RaylibException Throws if failed to export the Mesh.
*/
void ExportCode(const std::string& fileName) {
if (!::ExportMeshAsCode(*this, fileName.c_str())) {
throw RaylibException("Failed to export the Mesh");
}
}

/**
* Compute mesh bounding box limits
*/
Expand Down Expand Up @@ -210,6 +221,12 @@ class MeshUnmanaged : public ::Mesh {
* Load model from generated mesh
*/
operator raylib::Model() { return ::LoadModelFromMesh(*this); }

/**
* Returns whether or not the Mesh is valid.
*/
bool IsValid() { return ::IsModelValid(*this); }

protected:
void set(const ::Mesh& mesh) {
vertexCount = mesh.vertexCount;
Expand Down
28 changes: 25 additions & 3 deletions include/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ class Model : public ::Model {
return *this;
}

/**
* Update model animation pose
*/
Model& UpdateAnimationBones(const ::ModelAnimation& anim, int frame) {
::UpdateModelAnimationBones(*this, anim, frame);
return *this;
}

/**
* Check model animation skeleton match
*/
Expand Down Expand Up @@ -170,6 +178,20 @@ class Model : public ::Model {
::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
}

/**
* Draw a model as points
*/
void DrawPoints(::Vector3 position, float scale = 1.0f, ::Color tint = {255, 255, 255, 255}) {
::DrawModelPoints(*this, position, scale, tint);
}

/**
* Draw a model as points
*/
void DrawPoints(::Vector3 position, ::Vector3 rotationAxis, float rotationAngle = 0.0f, ::Vector3 scale = {1.0f, 1.0f, 1.0f}, ::Color tint = {255, 255, 255, 255}) {
::DrawModelPointsEx(*this, position, rotationAxis, rotationAngle, scale, tint);
}

/**
* Compute model bounding box limits (considers all meshes)
*/
Expand All @@ -183,7 +205,7 @@ class Model : public ::Model {
/**
* Determines whether or not the Model has data in it.
*/
bool IsReady() const { return ::IsModelReady(*this); }
bool IsValid() const { return ::IsModelValid(*this); }

/**
* Loads a Model from the given file.
Expand All @@ -192,7 +214,7 @@ class Model : public ::Model {
*/
void Load(const std::string& fileName) {
set(::LoadModel(fileName.c_str()));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Model from " + fileName);
}
}
Expand All @@ -204,7 +226,7 @@ class Model : public ::Model {
*/
void Load(const ::Mesh& mesh) {
set(::LoadModelFromMesh(mesh));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException("Failed to load Model from Mesh");
}
}
Expand Down
Loading