Skip to content

Commit 050aec5

Browse files
anderscCopilot
andcommitted
Upgrade to raylib 6.0 and simplify with raylib/raymath built-ins
- Update raylib from 5.0/5.5 to 6.0 across all build configs - Replace custom RLCommon.h utilities with raylib/raymath equivalents: lerpF -> Lerp, lerpColor -> ColorLerp, fadeColor -> Fade, lerpVector2 -> Vector2Lerp, distance -> Vector2Distance, catmullRom -> GetSplinePointCatmullRom, degToRad -> DEG2RAD - Add raymath.h include to RLCommon.h (available project-wide) - Use FetchContent fallback in main CMakeLists.txt for portability - Remove unused ZLIB dependency - Update CI workflows for raylib 6.0 (macOS builds from source) - Fix EPSILON macro conflict with raymath.h in RLLinearGauge.cpp - Update README.md and wasm/README.md with new version info - Update test_build/ and tools/ CMakeLists.txt Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent abd6a46 commit 050aec5

19 files changed

Lines changed: 123 additions & 176 deletions

.github/workflows/MacOS.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ jobs:
2323
- uses: actions/checkout@v4
2424

2525
- name: Install raylib
26-
run: brew install raylib
26+
run: |
27+
git clone --branch 6.0 https://github.com/raysan5/raylib.git raylib
28+
cd raylib
29+
mkdir build && cd build
30+
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ..
31+
make -j$(sysctl -n hw.ncpu)
32+
sudo make install
2733
2834
- name: Configure CMake
2935
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.

.github/workflows/ubuntu_x86_64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Install raylib
2626
run: |
2727
sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev xvfb
28-
git clone https://github.com/raysan5/raylib.git raylib
28+
git clone --branch 6.0 https://github.com/raysan5/raylib.git raylib
2929
cd raylib
3030
mkdir build && cd build
3131
cmake -DBUILD_SHARED_LIBS=ON ..

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
3535
- name: install raylib
3636
run: |
37-
git clone --branch 5.5 https://github.com/raysan5/raylib.git
37+
git clone --branch 6.0 https://github.com/raysan5/raylib.git
3838
cd raylib
3939
mkdir build
4040
cd build

CMakeLists.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@ project(cpp_charts)
33

44
set(CMAKE_CXX_STANDARD 20)
55

6-
find_package (raylib 5.0 REQUIRED)
7-
find_package (ZLIB REQUIRED)
8-
find_package (Threads REQUIRED)
9-
10-
message("Including raylib from: " ${raylib_INCLUDE_DIRS})
11-
message("Including ZLIB from: " ${ZLIB_INCLUDE_DIRS})
6+
find_package (raylib 6.0 QUIET)
7+
if (NOT raylib_FOUND)
8+
include(FetchContent)
9+
FetchContent_Declare(
10+
raylib
11+
GIT_REPOSITORY https://github.com/raysan5/raylib.git
12+
GIT_TAG 6.0
13+
GIT_SHALLOW TRUE
14+
)
15+
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
16+
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
17+
FetchContent_MakeAvailable(raylib)
18+
message(STATUS "Using FetchContent raylib 6.0")
19+
else()
20+
message(STATUS "Using system raylib: ${raylib_INCLUDE_DIRS}")
21+
include_directories(${raylib_INCLUDE_DIRS})
22+
endif()
1223

13-
include_directories(${raylib_INCLUDE_DIRS})
14-
include_directories(${ZLIB_INCLUDE_DIRS})
24+
find_package(Threads REQUIRED)
1525

1626
#gauges header files location
1727
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/charts)

README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,24 @@ chart.draw();
286286
## 📦 Integration into Your Project
287287
288288
### You need to have the following dependencies installed:
289-
- [raylib](https://www.raylib.com/) 5.0 or higher
290-
- [zlib](https://zlib.net/) (for certain features)
289+
- [raylib](https://www.raylib.com/) 6.0 or higher (auto-fetched if not found)
291290
- CMake 3.28 or higher
292291
293292
### MacOS (using Homebrew):
294293
295294
```bash
296-
brew install raylib zlib
295+
# raylib 6.0 will be fetched automatically by CMake if not installed
296+
# Or build from source:
297+
git clone --branch 6.0 https://github.com/raysan5/raylib.git
298+
cd raylib && mkdir build && cd build
299+
cmake -DBUILD_SHARED_LIBS=ON .. && make && sudo make install
297300
```
298301
### Ubuntu (using apt):
299302

300303
```bash
301-
sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev zlib1g-dev
304+
sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
302305
cd (temporary directory or where you want to build raylib)
303-
git clone --branch 5.5 https://github.com/raysan5/raylib.git raylib
306+
git clone --branch 6.0 https://github.com/raysan5/raylib.git raylib
304307
cd raylib
305308
mkdir build && cd build
306309
cmake -DBUILD_SHARED_LIBS=ON ..
@@ -316,14 +319,8 @@ See the windows build actions for reference. The below builds the x86_64 binarie
316319

317320

318321
```bash
319-
cd (temporary directory or where you want to build zlib)
320-
git clone --branch v1.3.1 https://github.com/madler/zlib.git
321-
cd zlib
322-
cmake -S . -DCMAKE_BUILD_TYPE=Release
323-
cmake --build . --target install --config Release
324-
325322
cd (temporary directory or where you want to build raylib)
326-
git clone --branch 5.5 https://github.com/raysan5/raylib.git
323+
git clone --branch 6.0 https://github.com/raysan5/raylib.git
327324
cd raylib
328325
mkdir build
329326
cd build
@@ -344,15 +341,21 @@ project(single_guage)
344341
345342
set(CMAKE_CXX_STANDARD 20)
346343
347-
find_package (raylib 5.0 REQUIRED)
348-
find_package (ZLIB REQUIRED)
349-
find_package (Threads REQUIRED)
350-
351-
message("Including raylib from: " ${raylib_INCLUDE_DIRS})
352-
message("Including ZLIB from: " ${ZLIB_INCLUDE_DIRS})
344+
find_package(raylib 6.0 QUIET)
345+
if (NOT raylib_FOUND)
346+
include(FetchContent)
347+
FetchContent_Declare(
348+
raylib
349+
GIT_REPOSITORY https://github.com/raysan5/raylib.git
350+
GIT_TAG 6.0
351+
GIT_SHALLOW TRUE
352+
)
353+
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
354+
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
355+
FetchContent_MakeAvailable(raylib)
356+
endif()
353357
354-
include_directories(${raylib_INCLUDE_DIRS})
355-
include_directories(${ZLIB_INCLUDE_DIRS})
358+
find_package(Threads REQUIRED)
356359
357360
include(FetchContent)
358361
FetchContent_Declare(
@@ -476,7 +479,7 @@ python3 -m http.server 8080
476479
- 🎨 Beautiful custom landing page with dark theme
477480
- ⚡ Fast loading with progress indicator
478481
- 📱 Fullscreen support
479-
- 🔧 Self-contained build (fetches raylib 5.5 automatically)
482+
- 🔧 Self-contained build (fetches raylib 6.0 automatically)
480483

481484
For complete build instructions, prerequisites, and troubleshooting, see **[wasm/README.md](wasm/README.md)**.
482485

@@ -602,8 +605,7 @@ CPP_CHARTS_SKIP_RAYLIB=1 ctest --output-on-failure
602605

603606
- **CMake** 3.28 or higher
604607
- **C++20** compiler
605-
- **raylib** 5.0 or higher
606-
- **zlib** (for certain features)
608+
- **raylib** 6.0 or higher
607609

608610
---
609611

src/RLCommon.h

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// RLCommon.h
22
#pragma once
33
#include "raylib.h"
4+
#include "raymath.h"
45
#include <cmath>
56

67
// Common utilities for raylib charts
7-
// All functions are in the RLCharts namespace to avoid conflicts
8+
// Leverages raylib/raymath built-in functions where possible (raylib 6.0+)
89

910
namespace RLCharts {
1011

@@ -15,7 +16,7 @@ inline T clamp01(T aValue) {
1516
(aValue > static_cast<T>(1) ? static_cast<T>(1) : aValue);
1617
}
1718

18-
// Template for clamping to arbitrary range
19+
// Template for clamping to arbitrary range (supports int and float)
1920
template<typename T>
2021
inline T clamp(T aValue, T aMin, T aMax) {
2122
return aValue < aMin ? aMin : (aValue > aMax ? aMax : aValue);
@@ -28,28 +29,6 @@ inline T clampIdx(T aValue, T aMaxLimit) {
2829
(aValue >= aMaxLimit ? aMaxLimit - static_cast<T>(1) : aValue);
2930
}
3031

31-
// Template for linear interpolation
32-
template<typename T>
33-
inline T lerp(T a, T b, float t) {
34-
return static_cast<T>(a + (b - a) * t);
35-
}
36-
37-
// Specialized lerp for floats (explicit to avoid casting overhead)
38-
inline float lerpF(float a, float b, float t) {
39-
return a + (b - a) * t;
40-
}
41-
42-
// Color interpolation with clamping
43-
inline Color lerpColor(const Color& a, const Color& b, float t) {
44-
t = clamp01(t);
45-
Color lResult;
46-
lResult.r = (unsigned char)(a.r + (int)((b.r - a.r) * t));
47-
lResult.g = (unsigned char)(a.g + (int)((b.g - a.g) * t));
48-
lResult.b = (unsigned char)(a.b + (int)((b.b - a.b) * t));
49-
lResult.a = (unsigned char)(a.a + (int)((b.a - a.a) * t));
50-
return lResult;
51-
}
52-
5332
// Template for min/max
5433
template<typename T>
5534
inline T minVal(T a, T b) {
@@ -61,16 +40,6 @@ inline T maxVal(T a, T b) {
6140
return a > b ? a : b;
6241
}
6342

64-
// Degree to radian conversion
65-
inline float degToRad(float aDeg) {
66-
return aDeg * PI / 180.0f;
67-
}
68-
69-
// Radian to degree conversion
70-
inline float radToDeg(float aRad) {
71-
return aRad * 180.0f / PI;
72-
}
73-
7443
// Calculate luminance of a color (for auto text color selection)
7544
inline float colorLuma(const Color& rColor) {
7645
return 0.2126f * rColor.r + 0.7152f * rColor.g + 0.0722f * rColor.b;
@@ -79,49 +48,13 @@ inline float colorLuma(const Color& rColor) {
7948
// Smooth approach function for exponential smoothing
8049
inline float approach(float a, float b, float aSpeedDt) {
8150
float lDiff = b - a;
82-
return a + lDiff * (lDiff * lDiff < 1e-8f ? 1.0f : clamp01(aSpeedDt));
51+
return a + lDiff * (lDiff * lDiff < 1e-8f ? 1.0f : Clamp(aSpeedDt, 0.0f, 1.0f));
8352
}
8453

8554
// Multiply alpha channel by a factor
8655
inline unsigned char mulAlpha(unsigned char a, float f) {
8756
float lValue = (float)a * f;
88-
if (lValue < 0.0f) lValue = 0.0f;
89-
if (lValue > 255.0f) lValue = 255.0f;
90-
return (unsigned char)(lValue + 0.5f);
91-
}
92-
93-
// Create a color with modified alpha (faded)
94-
inline Color fadeColor(Color aC, float aAlpha) {
95-
aC.a = (unsigned char)(aC.a * clamp01(aAlpha));
96-
return aC;
97-
}
98-
99-
// Vector2 linear interpolation
100-
inline Vector2 lerpVector2(const Vector2& a, const Vector2& b, float t) {
101-
return Vector2{ lerpF(a.x, b.x, t), lerpF(a.y, b.y, t) };
102-
}
103-
104-
// Vector2 distance
105-
inline float distance(const Vector2& a, const Vector2& b) {
106-
float lDx = a.x - b.x;
107-
float lDy = a.y - b.y;
108-
return sqrtf(lDx * lDx + lDy * lDy);
109-
}
110-
111-
// Catmull-Rom spline interpolation
112-
inline Vector2 catmullRom(const Vector2& aP0, const Vector2& aP1,
113-
const Vector2& aP2, const Vector2& aP3, float aT) {
114-
float lT2 = aT * aT;
115-
float lT3 = lT2 * aT;
116-
float lX = 0.5f * ((2.0f * aP1.x) +
117-
(-aP0.x + aP2.x) * aT +
118-
(2 * aP0.x - 5 * aP1.x + 4 * aP2.x - aP3.x) * lT2 +
119-
(-aP0.x + 3 * aP1.x - 3 * aP2.x + aP3.x) * lT3);
120-
float lY = 0.5f * ((2.0f * aP1.y) +
121-
(-aP0.y + aP2.y) * aT +
122-
(2 * aP0.y - 5 * aP1.y + 4 * aP2.y - aP3.y) * lT2 +
123-
(-aP0.y + 3 * aP1.y - 3 * aP2.y + aP3.y) * lT3);
124-
return { lX, lY };
57+
return (unsigned char)Clamp(lValue + 0.5f, 0.0f, 255.0f);
12558
}
12659

12760
} // namespace RLCharts

src/charts/RLGauge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void RLGauge::recomputeGeometry(){
7272
const float lLen = lMajor ? mStyle.mMajorTickLen : mStyle.mTickLen;
7373
const float lRadiusStart = lInnerR - lLen;
7474
const float lRadiusEnd = lInnerR - 2.0f; // small gap from ring
75-
const float lAngleRad = RLCharts::degToRad(lAngleDeg);
75+
const float lAngleRad = lAngleDeg * DEG2RAD;
7676
const float lCos = cosf(lAngleRad);
7777
const float lSin = sinf(lAngleRad);
7878
Vector2 lP0{ mCenter.x + (lCos * lRadiusStart), mCenter.y + (lSin * lRadiusStart) };
@@ -116,7 +116,7 @@ void RLGauge::draw() const{
116116
// needle
117117
if (mStyle.mShowNeedle){
118118
float lAng = valueToAngle(mValue);
119-
float lAngRad = RLCharts::degToRad(lAng);
119+
float lAngRad = lAng * DEG2RAD;
120120
float lNeedleRadius = mRadius * mStyle.mNeedleRadiusScale;
121121
Vector2 lTip{ mCenter.x + (cosf(lAngRad) * lNeedleRadius), mCenter.y + (sinf(lAngRad) * lNeedleRadius) };
122122
DrawLineEx(mCenter, lTip, mStyle.mNeedleWidth, mStyle.mNeedleColor);

src/charts/RLHeatMap3D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ void RLHeatMap3D::rebuildLut() {
673673
lIdx0 = std::max(lIdx0, 0);
674674

675675
const float lLocalT = lScaled - (float)lIdx0;
676-
mLut[i] = RLCharts::lerpColor(mPaletteStops[(size_t)lIdx0], mPaletteStops[(size_t)lIdx1], lLocalT);
676+
mLut[i] = ColorLerp(mPaletteStops[(size_t)lIdx0], mPaletteStops[(size_t)lIdx1], lLocalT);
677677
}
678678

679679
mLutDirty = false;

src/charts/RLLinearGauge.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
constexpr float HALF = 0.5f;
1111
constexpr int VALUE_BUFFER_SIZE = 64;
1212
constexpr float MIN_TRACK_LENGTH = 20.0f;
13-
constexpr float EPSILON = 1e-6f;
13+
constexpr float FLOAT_EPSILON = 1e-6f;
1414

1515
RLLinearGauge::RLLinearGauge(Rectangle aBounds, float aMinValue, float aMaxValue,
1616
RLLinearGaugeOrientation aOrientation,
@@ -135,7 +135,7 @@ void RLLinearGauge::setChannelValue(int aIndex, float aValue) {
135135
}
136136

137137
// Detect clipping (value at or near max)
138-
if (mChannels[(size_t)aIndex].mValue >= mMaxValue - EPSILON) {
138+
if (mChannels[(size_t)aIndex].mValue >= mMaxValue - FLOAT_EPSILON) {
139139
mClipStates[(size_t)aIndex] = true;
140140
mClipTimers[(size_t)aIndex] = mStyle.mVuStyle.mClipFlashDuration;
141141
}
@@ -568,7 +568,7 @@ void RLLinearGauge::drawTitle() const {
568568
// ============================================================================
569569

570570
float RLLinearGauge::linearToDb(float aLinear) const {
571-
if (aLinear <= EPSILON) {
571+
if (aLinear <= FLOAT_EPSILON) {
572572
return mStyle.mVuStyle.mDbMin;
573573
}
574574
float lDb = 20.0f * log10f(aLinear);
@@ -659,14 +659,14 @@ void RLLinearGauge::drawVuMeterChannel(int aIndex, Rectangle aBounds) const {
659659
lNormalized = std::max(0.0f, std::min(1.0f, lNormalized));
660660

661661
// Apply dB scale if enabled
662-
if (mStyle.mVuStyle.mUseDbScale && lNormalized > EPSILON) {
662+
if (mStyle.mVuStyle.mUseDbScale && lNormalized > FLOAT_EPSILON) {
663663
float lDb = linearToDb(lNormalized);
664664
float lDbRange = mStyle.mVuStyle.mDbMax - mStyle.mVuStyle.mDbMin;
665665
lNormalized = (lDb - mStyle.mVuStyle.mDbMin) / lDbRange;
666666
lNormalized = std::max(0.0f, std::min(1.0f, lNormalized));
667667
}
668668

669-
if (lNormalized <= EPSILON) {
669+
if (lNormalized <= FLOAT_EPSILON) {
670670
return;
671671
}
672672

@@ -756,14 +756,14 @@ void RLLinearGauge::drawVuMeterPeakMarker(int aIndex, Rectangle aBounds) const {
756756
lNormalized = std::max(0.0f, std::min(1.0f, lNormalized));
757757

758758
// Apply dB scale if enabled
759-
if (mStyle.mVuStyle.mUseDbScale && lNormalized > EPSILON) {
759+
if (mStyle.mVuStyle.mUseDbScale && lNormalized > FLOAT_EPSILON) {
760760
float lDb = linearToDb(lNormalized);
761761
float lDbRange = mStyle.mVuStyle.mDbMax - mStyle.mVuStyle.mDbMin;
762762
lNormalized = (lDb - mStyle.mVuStyle.mDbMin) / lDbRange;
763763
lNormalized = std::max(0.0f, std::min(1.0f, lNormalized));
764764
}
765765

766-
if (lNormalized <= EPSILON) {
766+
if (lNormalized <= FLOAT_EPSILON) {
767767
return;
768768
}
769769

src/charts/RLLogPlot.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ void RLLogPlot::drawLogTrace(const RLLogPlotTrace& rTrace, Rectangle aPlotRect)
650650
const Vector2 lUpperPt = mapLogPoint(lLogX, lLogUpper, aPlotRect);
651651

652652
const float lVis = (i < rTrace.mVisibility.size()) ? rTrace.mVisibility[i] : 1.0f;
653-
const Color lDrawColor = RLCharts::fadeColor(lConfColor, lVis);
653+
const Color lDrawColor = Fade(lConfColor, lVis);
654654

655655
if (rTrace.mStyle.mConfidenceAsBars) {
656656
// Error bars
@@ -690,7 +690,7 @@ void RLLogPlot::drawLogTrace(const RLLogPlotTrace& rTrace, Rectangle aPlotRect)
690690
// Draw connecting lines
691691
for (size_t i = 0; i < lScreenPoints.size() - 1; ++i) {
692692
const float lVis = (i < rTrace.mVisibility.size()) ? rTrace.mVisibility[i] : 1.0f;
693-
const Color lDrawColor = RLCharts::fadeColor(rTrace.mStyle.mLineColor, lVis);
693+
const Color lDrawColor = Fade(rTrace.mStyle.mLineColor, lVis);
694694
DrawLineEx(lScreenPoints[i], lScreenPoints[i + 1],
695695
rTrace.mStyle.mLineThickness, lDrawColor);
696696
}
@@ -704,7 +704,7 @@ void RLLogPlot::drawLogTrace(const RLLogPlotTrace& rTrace, Rectangle aPlotRect)
704704

705705
for (size_t i = 0; i < lScreenPoints.size(); ++i) {
706706
const float lVis = (i < rTrace.mVisibility.size()) ? rTrace.mVisibility[i] : 1.0f;
707-
const Color lDrawColor = RLCharts::fadeColor(lPointColor, lVis);
707+
const Color lDrawColor = Fade(lPointColor, lVis);
708708
DrawCircleV(lScreenPoints[i], rTrace.mStyle.mPointRadius, lDrawColor);
709709

710710
// Outline for visibility

0 commit comments

Comments
 (0)