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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ if(BUILD_RAYLIB_CPP_EXAMPLES)
)
endif()
endif()

# ignore unused functions
if (MSVC)
target_compile_options(raylib_cpp INTERFACE /wd4505)
else()
target_compile_options(raylib_cpp INTERFACE -Wno-unused-function)
endif()
16 changes: 8 additions & 8 deletions examples/shaders/shaders_basic_lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ int main(void)

// Define the camera to look into our 3d world
raylib::Camera camera;
camera.position = (Vector3){ 2.0f, 4.0f, 6.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.position = Vector3{ 2.0f, 4.0f, 6.0f }; // Camera position
camera.target = Vector3{ 0.0f, 0.5f, 0.0f }; // Camera looking at point
camera.up = Vector3{ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type

Expand All @@ -70,10 +70,10 @@ int main(void)

// Create lights
std::array<Light, MAX_LIGHTS> lights = {
CreateLight(LIGHT_POINT, (Vector3) {-2, 1, -2}, Vector3Zero(), YELLOW, shader),
CreateLight(LIGHT_POINT, (Vector3) {2, 1, 2}, Vector3Zero(), RED, shader),
CreateLight(LIGHT_POINT, (Vector3) {-2, 1, 2}, Vector3Zero(), GREEN, shader),
CreateLight(LIGHT_POINT, (Vector3) {2, 1, -2}, Vector3Zero(), BLUE, shader),
CreateLight(LIGHT_POINT, Vector3 {-2, 1, -2}, Vector3Zero(), YELLOW, shader),
CreateLight(LIGHT_POINT, Vector3 {2, 1, 2}, Vector3Zero(), RED, shader),
CreateLight(LIGHT_POINT, Vector3 {-2, 1, 2}, Vector3Zero(), GREEN, shader),
CreateLight(LIGHT_POINT, Vector3 {2, 1, -2}, Vector3Zero(), BLUE, shader),
};

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
Expand Down Expand Up @@ -110,7 +110,7 @@ int main(void)

BeginShaderMode(shader);

DrawPlane(Vector3Zero(), (Vector2) { 10.0, 10.0 }, WHITE);
DrawPlane(Vector3Zero(), Vector2 { 10.0, 10.0 }, WHITE);
DrawCube(Vector3Zero(), 2.0, 4.0, 2.0, WHITE);

EndShaderMode();
Expand Down
40 changes: 20 additions & 20 deletions examples/shaders/shaders_basic_pbr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ int main()

// Define the camera to look into our 3d world
raylib::Camera camera;
camera.position = (Vector3){ 2.0f, 2.0f, 6.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.position = Vector3{ 2.0f, 2.0f, 6.0f }; // Camera position
camera.target = Vector3{ 0.0f, 0.5f, 0.0f }; // Camera looking at point
camera.up = Vector3{ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type

Expand All @@ -117,8 +117,8 @@ int main()

// Setup ambient color and intensity parameters
float ambientIntensity = 0.02f;
raylib::Color ambientColor = (Color){ 26, 32, 135, 255 };
raylib::Vector3 ambientColorNormalized = (Vector3){ ambientColor.r/255.0f, ambientColor.g/255.0f, ambientColor.b/255.0f };
raylib::Color ambientColor = Color{ 26, 32, 135, 255 };
raylib::Vector3 ambientColorNormalized = Vector3{ ambientColor.r/255.0f, ambientColor.g/255.0f, ambientColor.b/255.0f };
shader.SetValue(shader.GetLocation("ambientColor"), &ambientColorNormalized, SHADER_UNIFORM_VEC3);
shader.SetValue(shader.GetLocation("ambient"), &ambientIntensity, SHADER_UNIFORM_FLOAT);

Expand All @@ -142,7 +142,7 @@ int main()
car.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.0f;
car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.0f;
car.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
car.materials[0].maps[MATERIAL_MAP_EMISSION].color = (Color){ 255, 162, 0, 255 };
car.materials[0].maps[MATERIAL_MAP_EMISSION].color = Color{ 255, 162, 0, 255 };

// Setup materials[0].maps default textures
car.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = LoadTexture("resources/old_car_d.png");
Expand Down Expand Up @@ -172,15 +172,15 @@ int main()

// Models texture tiling parameter can be stored in the Material struct if required (CURRENTLY NOT USED)
// NOTE: Material.params[4] are available for generic parameters storage (float)
Vector2 carTextureTiling = (Vector2){ 0.5f, 0.5f };
Vector2 floorTextureTiling = (Vector2){ 0.5f, 0.5f };
Vector2 carTextureTiling = Vector2{ 0.5f, 0.5f };
Vector2 floorTextureTiling = Vector2{ 0.5f, 0.5f };

// Create some lights
std::array<Light, MAX_LIGHTS> lights = {
CreateLight(0, LightType::POINT, (Vector3) {-1.0f, 1.0f, -2.0f}, (Vector3) {0.0f, 0.0f, 0.0f}, YELLOW, 4.0f, shader),
CreateLight(1, LightType::POINT, (Vector3){ 2.0f, 1.0f, 1.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, GREEN, 3.3f, shader),
CreateLight(2, LightType::POINT, (Vector3){ -2.0f, 1.0f, 1.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, RED, 8.3f, shader),
CreateLight(3, LightType::POINT, (Vector3){ 1.0f, 1.0f, -2.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, BLUE, 2.0f, shader),
CreateLight(0, LightType::POINT, Vector3{-1.0f, 1.0f, -2.0f}, Vector3{0.0f, 0.0f, 0.0f}, YELLOW, 4.0f, shader),
CreateLight(1, LightType::POINT, Vector3{ 2.0f, 1.0f, 1.0f }, Vector3{ 0.0f, 0.0f, 0.0f }, GREEN, 3.3f, shader),
CreateLight(2, LightType::POINT, Vector3{ -2.0f, 1.0f, 1.0f }, Vector3{ 0.0f, 0.0f, 0.0f }, RED, 8.3f, shader),
CreateLight(3, LightType::POINT, Vector3{ 1.0f, 1.0f, -2.0f }, Vector3{ 0.0f, 0.0f, 0.0f }, BLUE, 2.0f, shader),
};

// Setup material texture maps usage in shader
Expand Down Expand Up @@ -228,7 +228,7 @@ int main()
raylib::Vector4 floorEmissiveColor = ColorNormalize(floor.materials[0].maps[MATERIAL_MAP_EMISSION].color);
SetShaderValue(shader, emissiveColorLoc, &floorEmissiveColor, SHADER_UNIFORM_VEC4);

DrawModel(floor, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model
DrawModel(floor, Vector3{ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model

// Set old car model texture tiling, emissive color and emissive intensity parameters on shader
SetShaderValue(shader, textureTilingLoc, &carTextureTiling, SHADER_UNIFORM_VEC2);
Expand All @@ -237,15 +237,15 @@ int main()
float emissiveIntensity = 0.01f;
SetShaderValue(shader, emissiveIntensityLoc, &emissiveIntensity, SHADER_UNIFORM_FLOAT);

car.Draw((Vector3){ 0.0f, 0.0f, 0.0f }, 0.005f, WHITE); // Draw car model
car.Draw(Vector3{ 0.0f, 0.0f, 0.0f }, 0.005f, WHITE); // Draw car model

// Draw spheres to show the lights positions
for (const auto& light : lights)
{
Color lightColor = (Color){ static_cast<unsigned char>(light.color[0]*255),
static_cast<unsigned char>(light.color[1]*255),
static_cast<unsigned char>(light.color[2]*255),
static_cast<unsigned char>(light.color[3]*255) };
Color lightColor = Color{ static_cast<unsigned char>(light.color[0]*255),
static_cast<unsigned char>(light.color[1]*255),
static_cast<unsigned char>(light.color[2]*255),
static_cast<unsigned char>(light.color[3]*255) };

if (light.enabled) DrawSphereEx(light.position, 0.2f, 8, 8, lightColor);
else DrawSphereWires(light.position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
Expand All @@ -267,12 +267,12 @@ int main()
//--------------------------------------------------------------------------------------
// Unbind (disconnect) shader from car.material[0]
// to avoid UnloadMaterial() trying to unload it automatically
car.materials[0].shader = (Shader){ 0 };
car.materials[0].shader = Shader{ 0 };
UnloadMaterial(car.materials[0]);
car.materials[0].maps = NULL;
//UnloadModel(car);

floor.materials[0].shader = (Shader){ 0 };
floor.materials[0].shader = Shader{ 0 };
UnloadMaterial(floor.materials[0]);
floor.materials[0].maps = NULL;
//UnloadModel(floor);
Expand Down
6 changes: 3 additions & 3 deletions include/AudioStreamUnmanaged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class AudioStreamUnmanaged : public ::AudioStream {
/**
* Check if any audio stream buffers require refill.
*/
[[nodiscard]] bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
RLCPP_NODISCARD bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }

/**
* Play audio stream.
Expand Down Expand Up @@ -116,7 +116,7 @@ class AudioStreamUnmanaged : public ::AudioStream {
/**
* Check if audio stream is playing.
*/
[[nodiscard]] bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
RLCPP_NODISCARD bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }

/**
* Stop audio stream.
Expand Down Expand Up @@ -182,7 +182,7 @@ class AudioStreamUnmanaged : public ::AudioStream {
/**
* Retrieve whether or not the audio stream is ready.
*/
[[nodiscard]] bool IsValid() const { return ::IsAudioStreamValid(*this); }
RLCPP_NODISCARD bool IsValid() const { return ::IsAudioStreamValid(*this); }

protected:
void set(const ::AudioStream& stream) {
Expand Down
6 changes: 3 additions & 3 deletions include/BoundingBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class BoundingBox : public ::BoundingBox {
/**
* Detect collision between two boxes
*/
[[nodiscard]] bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
RLCPP_NODISCARD bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }

/**
* Detect collision between box and sphere
*/
[[nodiscard]] bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
RLCPP_NODISCARD bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }

/**
* Detect collision between ray and bounding box
*/
[[nodiscard]] bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
RLCPP_NODISCARD bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }

/**
* Get collision information between ray and bounding box
Expand Down
6 changes: 3 additions & 3 deletions include/Camera2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class Camera2D : public ::Camera2D {
/**
* Returns camera 2d transform matrix
*/
[[nodiscard]] Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
RLCPP_NODISCARD Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }

/**
* Returns the world space position for a 2d camera screen space position
*/
[[nodiscard]] Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
RLCPP_NODISCARD Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }

/**
* Returns the screen space position for a 2d world space position
*/
[[nodiscard]] Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
RLCPP_NODISCARD Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
protected:
void set(const ::Camera2D& camera) {
offset = camera.offset;
Expand Down
14 changes: 7 additions & 7 deletions include/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ class Color : public ::Color {
/**
* Returns hexadecimal value for a Color
*/
[[nodiscard]] int ToInt() const { return ::ColorToInt(*this); }
RLCPP_NODISCARD int ToInt() const { return ::ColorToInt(*this); }

/**
* Returns hexadecimal value for a Color
*/
explicit operator int() const { return ::ColorToInt(*this); }

[[nodiscard]] std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
RLCPP_NODISCARD std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }

explicit operator std::string() const { return ToString(); }

/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
[[nodiscard]] Color Fade(float alpha) const { return ::Fade(*this, alpha); }
RLCPP_NODISCARD Color Fade(float alpha) const { return ::Fade(*this, alpha); }

/**
* Returns Color normalized as float [0..1]
*/
[[nodiscard]] Vector4 Normalize() const { return ::ColorNormalize(*this); }
RLCPP_NODISCARD Vector4 Normalize() const { return ::ColorNormalize(*this); }

/**
* Returns Color from normalized values [0..1]
Expand All @@ -72,7 +72,7 @@ class Color : public ::Color {
/**
* Returns HSV values for a Color
*/
[[nodiscard]] Vector3 ToHSV() const { return ::ColorToHSV(*this); }
RLCPP_NODISCARD Vector3 ToHSV() const { return ::ColorToHSV(*this); }

GETTERSETTER(unsigned char, R, r)
GETTERSETTER(unsigned char, G, g)
Expand Down Expand Up @@ -206,7 +206,7 @@ class Color : public ::Color {
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
[[nodiscard]] Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
RLCPP_NODISCARD Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }

Color Lerp(::Color color2, float factor) {
return ::ColorLerp(*this, color2, factor);
Expand All @@ -215,7 +215,7 @@ class Color : public ::Color {
/**
* Returns src alpha-blended into dst color with tint
*/
[[nodiscard]] Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
RLCPP_NODISCARD Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }

static Color LightGray() { return LIGHTGRAY; }
static Color Gray() { return GRAY; }
Expand Down
4 changes: 2 additions & 2 deletions include/FileText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class FileText {
GETTER(const char*, Data, data)
GETTER(unsigned int, Length, length)

[[nodiscard]] const char* c_str() const { return data; }
RLCPP_NODISCARD const char* c_str() const { return data; }

[[nodiscard]] std::string ToString() const { return data; }
RLCPP_NODISCARD std::string ToString() const { return data; }
explicit operator std::string() const { return data; }

void Load(const std::string& fileName) { Load(fileName.c_str()); }
Expand Down
14 changes: 7 additions & 7 deletions include/FontUnmanaged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class FontUnmanaged : public ::Font {
* Get the texture atlas containing the glyphs.
*/
TextureUnmanaged GetTexture() { return texture; }
[[nodiscard]] TextureUnmanaged GetTexture() const { return texture; }
RLCPP_NODISCARD TextureUnmanaged GetTexture() const { return texture; }

/**
* Set the texture atlas containing the glyphs.
Expand Down Expand Up @@ -167,7 +167,7 @@ class FontUnmanaged : public ::Font {
/**
* Returns if the font is ready to be used.
*/
[[nodiscard]] bool IsValid() const { return ::IsFontValid(*this); }
RLCPP_NODISCARD bool IsValid() const { return ::IsFontValid(*this); }

/**
* Draw text using font and additional parameters.
Expand Down Expand Up @@ -265,33 +265,33 @@ class FontUnmanaged : public ::Font {
/**
* Measure string size for Font.
*/
[[nodiscard]] Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
RLCPP_NODISCARD Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text, fontSize, spacing);
}

/**
* Measure string size for Font.
*/
[[nodiscard]] Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
RLCPP_NODISCARD Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
}

/**
* Get index position for a unicode character on font.
*/
[[nodiscard]] int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
RLCPP_NODISCARD int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }

/**
* Create an image from text (custom sprite font).
*/
[[nodiscard]] ::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
RLCPP_NODISCARD ::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text, fontSize, spacing, tint);
}

/**
* Create an image from text (custom sprite font).
*/
[[nodiscard]] ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
RLCPP_NODISCARD ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
}

Expand Down
Loading
Loading