mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-19 11:03:27 +00:00
Compare commits
24 Commits
4567cfa318
...
feature/vm
| Author | SHA1 | Date | |
|---|---|---|---|
| cb45b9bb04 | |||
| f3656f9d2c | |||
| 7ebbed6763 | |||
| e271bccaf5 | |||
| 50765f69c5 | |||
| 1169534133 | |||
| 783501aab9 | |||
| 1a79566731 | |||
|
|
9183406e7a | ||
|
|
b592af91a9 | ||
|
|
af9c043e95 | ||
| 2aaa8633b9 | |||
| 0d1cc2088f | |||
| 260b3b97f9 | |||
| e0904690e6 | |||
| 7021d9d365 | |||
| 862d52593a | |||
| 97a3111791 | |||
| a9bec00973 | |||
|
|
66debb46fa | ||
|
|
b8323d3bc0 | ||
|
|
f363fa6f1a | ||
|
|
0546272493 | ||
|
|
58801bfab3 |
4
.github/FUNDING.yml
vendored
Normal file
4
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
open_collective: libomathorg
|
||||||
|
github: orange-cpp
|
||||||
618
.github/workflows/release.yml
vendored
Normal file
618
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,618 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: release-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
##############################################################################
|
||||||
|
# 1) Linux – Clang / Ninja
|
||||||
|
##############################################################################
|
||||||
|
linux-release:
|
||||||
|
name: ${{ matrix.name }}
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: Linux (Clang) (x64-linux)
|
||||||
|
triplet: x64-linux
|
||||||
|
runner: ubuntu-latest
|
||||||
|
preset: linux-release-vcpkg
|
||||||
|
archive: omath-linux-x64
|
||||||
|
install_cmd: |
|
||||||
|
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
|
sudo add-apt-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main"
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y git build-essential cmake ninja-build \
|
||||||
|
zip unzip curl pkg-config ca-certificates \
|
||||||
|
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
|
||||||
|
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
|
||||||
|
- name: Linux (Clang) (x86-linux)
|
||||||
|
triplet: x86-linux
|
||||||
|
runner: ubuntu-latest
|
||||||
|
preset: linux-release-vcpkg-x86
|
||||||
|
archive: omath-linux-x86
|
||||||
|
install_cmd: |
|
||||||
|
# Add LLVM 21 repository
|
||||||
|
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
|
sudo add-apt-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main"
|
||||||
|
# Add GCC Toolchain PPA
|
||||||
|
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu plucky main universe"
|
||||||
|
# Enable i386 architecture
|
||||||
|
sudo dpkg --add-architecture i386
|
||||||
|
sudo apt-get update
|
||||||
|
# Install Clang 21
|
||||||
|
sudo apt-get install -y git build-essential cmake ninja-build \
|
||||||
|
zip unzip curl pkg-config ca-certificates \
|
||||||
|
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
|
||||||
|
sudo apt-get install -y -t plucky binutils
|
||||||
|
# Install GCC 15 with multilib support
|
||||||
|
sudo apt-get install -y gcc-15-multilib g++-15-multilib
|
||||||
|
# Set up alternatives for Clang
|
||||||
|
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
|
||||||
|
# Set up alternatives for GCC
|
||||||
|
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 100
|
||||||
|
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-15 100
|
||||||
|
- name: Linux (Clang) (arm64-linux)
|
||||||
|
triplet: arm64-linux
|
||||||
|
runner: ubuntu-24.04-arm
|
||||||
|
preset: linux-release-vcpkg-arm64
|
||||||
|
archive: omath-linux-arm64
|
||||||
|
install_cmd: |
|
||||||
|
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
|
sudo add-apt-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main"
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y git build-essential cmake ninja-build \
|
||||||
|
zip unzip curl pkg-config ca-certificates \
|
||||||
|
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
|
||||||
|
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Install basic tool-chain
|
||||||
|
shell: bash
|
||||||
|
run: ${{ matrix.install_cmd }}
|
||||||
|
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DVCPKG_INSTALL_OPTIONS="--allow-unsupported" \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
shell: bash
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: bash
|
||||||
|
run: tar -czf ${{ matrix.archive }}.tar.gz -C staging .
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.tar.gz" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 2) Windows – MSVC / Ninja
|
||||||
|
##############################################################################
|
||||||
|
windows-release:
|
||||||
|
name: ${{ matrix.name }}
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: Windows (MSVC) (x64-windows)
|
||||||
|
runner: windows-latest
|
||||||
|
arch: amd64
|
||||||
|
preset: windows-release-vcpkg
|
||||||
|
triplet: x64-windows
|
||||||
|
archive: omath-windows-x64
|
||||||
|
- name: Windows (MSVC) (x86-windows)
|
||||||
|
runner: windows-latest
|
||||||
|
arch: amd64_x86
|
||||||
|
preset: windows-release-vcpkg-x86
|
||||||
|
triplet: x86-windows
|
||||||
|
archive: omath-windows-x86
|
||||||
|
- name: Windows (MSVC) (arm64-windows)
|
||||||
|
runner: windows-11-arm
|
||||||
|
arch: arm64
|
||||||
|
preset: windows-release-vcpkg-arm64
|
||||||
|
triplet: arm64-windows
|
||||||
|
archive: omath-windows-arm64
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Ninja
|
||||||
|
uses: seanmiddleditch/gha-setup-ninja@v4
|
||||||
|
|
||||||
|
- name: Set up MSVC developer command-prompt
|
||||||
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
with:
|
||||||
|
arch: ${{ matrix.arch }}
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
shell: bash
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: pwsh
|
||||||
|
run: Compress-Archive -Path staging\* -DestinationPath "${{ matrix.archive }}.zip"
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.zip" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 3) macOS – AppleClang / Ninja
|
||||||
|
##############################################################################
|
||||||
|
macos-release:
|
||||||
|
name: ${{ matrix.name }}
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: macOS (AppleClang) (arm64-osx)
|
||||||
|
runner: macos-latest
|
||||||
|
preset: darwin-release-vcpkg
|
||||||
|
triplet: arm64-osx
|
||||||
|
archive: omath-macos-arm64
|
||||||
|
- name: macOS (AppleClang) (x64-osx)
|
||||||
|
runner: macos-15-intel
|
||||||
|
preset: darwin-release-vcpkg-x64
|
||||||
|
triplet: x64-osx
|
||||||
|
archive: omath-macos-x64
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Install basic tool-chain with Homebrew
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
brew install cmake ninja
|
||||||
|
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
shell: bash
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: bash
|
||||||
|
run: tar -czf ${{ matrix.archive }}.tar.gz -C staging .
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.tar.gz" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 4) iOS – AppleClang / Xcode / arm64-ios
|
||||||
|
##############################################################################
|
||||||
|
ios-release:
|
||||||
|
name: iOS (AppleClang) (${{ matrix.triplet }})
|
||||||
|
runs-on: macOS-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- triplet: arm64-ios
|
||||||
|
preset: ios-release-vcpkg
|
||||||
|
archive: omath-ios-arm64
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Install CMake tooling
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
brew install cmake ninja
|
||||||
|
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DVCPKG_INSTALL_OPTIONS="--allow-unsupported" \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --build cmake-build/build/${{ matrix.preset }} --config Release --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
shell: bash
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: bash
|
||||||
|
run: tar -czf ${{ matrix.archive }}.tar.gz -C staging .
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.tar.gz" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 5) FreeBSD – Clang / Ninja
|
||||||
|
##############################################################################
|
||||||
|
freebsd-release:
|
||||||
|
name: FreeBSD (Clang) (${{ matrix.triplet }})
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- triplet: x64-freebsd
|
||||||
|
preset: freebsd-release-vcpkg
|
||||||
|
arch: x86-64
|
||||||
|
archive: omath-freebsd-x64
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/tmp/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Build and Package
|
||||||
|
uses: cross-platform-actions/action@v0.31.0
|
||||||
|
with:
|
||||||
|
operating_system: freebsd
|
||||||
|
architecture: ${{ matrix.arch }}
|
||||||
|
version: '15.0'
|
||||||
|
memory: '12G'
|
||||||
|
cpu_count: 4
|
||||||
|
run: |
|
||||||
|
sudo pkg install -y git curl zip unzip gmake llvm gsed bash perl5 openssl 7-zip coreutils cmake ninja pkgconf patchelf
|
||||||
|
git config --global --add safe.directory `pwd`
|
||||||
|
# Build vcpkg in /tmp to avoid sshfs timestamp sync issues
|
||||||
|
export VCPKG_ROOT=/tmp/vcpkg
|
||||||
|
rm -rf "$VCPKG_ROOT"
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
cd -
|
||||||
|
export VCPKG_FORCE_SYSTEM_BINARIES=0
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2" \
|
||||||
|
-DVCPKG_INSTALL_OPTIONS="--allow-unsupported"
|
||||||
|
cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
tar -czf ${{ matrix.archive }}.tar.gz -C staging .
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.tar.gz" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 6) Android NDK – Clang / Ninja
|
||||||
|
##############################################################################
|
||||||
|
android-release:
|
||||||
|
name: Android NDK (${{ matrix.triplet }})
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- triplet: arm-neon-android
|
||||||
|
preset: android-arm-neon-release-vcpkg
|
||||||
|
archive: omath-android-arm-neon
|
||||||
|
- triplet: arm64-android
|
||||||
|
preset: android-arm64-release-vcpkg
|
||||||
|
archive: omath-android-arm64
|
||||||
|
- triplet: x64-android
|
||||||
|
preset: android-x64-release-vcpkg
|
||||||
|
archive: omath-android-x64
|
||||||
|
- triplet: x86-android
|
||||||
|
preset: android-x86-release-vcpkg
|
||||||
|
archive: omath-android-x86
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
ANDROID_NDK_HOME: ${{ github.workspace }}/android-ndk
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Android NDK
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
NDK_VERSION="r28b"
|
||||||
|
NDK_ZIP="android-ndk-${NDK_VERSION}-linux.zip"
|
||||||
|
wget -q "https://dl.google.com/android/repository/${NDK_ZIP}"
|
||||||
|
unzip -q "${NDK_ZIP}" -d "${{ github.workspace }}"
|
||||||
|
mv "${{ github.workspace }}/android-ndk-${NDK_VERSION}" "$ANDROID_NDK_HOME"
|
||||||
|
rm "${NDK_ZIP}"
|
||||||
|
echo "ANDROID_NDK_HOME=${ANDROID_NDK_HOME}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Install basic tool-chain
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ninja-build cmake
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DVCPKG_INSTALL_OPTIONS="--allow-unsupported" \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
shell: bash
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: bash
|
||||||
|
run: tar -czf ${{ matrix.archive }}.tar.gz -C staging .
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.tar.gz" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 7) WebAssembly (Emscripten) – Clang / Ninja / wasm32-emscripten
|
||||||
|
##############################################################################
|
||||||
|
wasm-release:
|
||||||
|
name: WebAssembly (Emscripten) (${{ matrix.triplet }})
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- triplet: wasm32-emscripten
|
||||||
|
preset: wasm-release-vcpkg
|
||||||
|
archive: omath-wasm32
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install basic tool-chain
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ninja-build
|
||||||
|
|
||||||
|
- name: Setup Emscripten
|
||||||
|
uses: mymindstorm/setup-emsdk@v14
|
||||||
|
with:
|
||||||
|
version: 'latest'
|
||||||
|
|
||||||
|
- name: Verify Emscripten
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "EMSDK=$EMSDK"
|
||||||
|
emcc --version
|
||||||
|
ls -la "$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DVCPKG_INSTALL_OPTIONS="--allow-unsupported" \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
shell: bash
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: bash
|
||||||
|
run: tar -czf ${{ matrix.archive }}.tar.gz -C staging .
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.tar.gz" --clobber
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 8) Windows MSYS2 MinGW – GCC / Ninja
|
||||||
|
##############################################################################
|
||||||
|
mingw-release:
|
||||||
|
name: ${{ matrix.name }}
|
||||||
|
runs-on: windows-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: MINGW64 (MSYS2) (x64-mingw-dynamic)
|
||||||
|
msystem: MINGW64
|
||||||
|
pkg_prefix: mingw-w64-x86_64
|
||||||
|
preset: mingw-release-vcpkg
|
||||||
|
archive: omath-mingw64-x64
|
||||||
|
- name: UCRT64 (MSYS2) (x64-mingw-dynamic)
|
||||||
|
msystem: UCRT64
|
||||||
|
pkg_prefix: mingw-w64-ucrt-x86_64
|
||||||
|
preset: mingw-release-vcpkg
|
||||||
|
archive: omath-ucrt64-x64
|
||||||
|
- name: MINGW32 (MSYS2) (x86-mingw-dynamic)
|
||||||
|
msystem: MINGW32
|
||||||
|
pkg_prefix: mingw-w64-i686
|
||||||
|
preset: mingw32-release-vcpkg
|
||||||
|
archive: omath-mingw32-x86
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: msys2 {0}
|
||||||
|
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Setup MSYS2
|
||||||
|
uses: msys2/setup-msys2@v2
|
||||||
|
with:
|
||||||
|
msystem: ${{ matrix.msystem }}
|
||||||
|
update: true
|
||||||
|
install: >-
|
||||||
|
${{ matrix.pkg_prefix }}-toolchain
|
||||||
|
${{ matrix.pkg_prefix }}-cmake
|
||||||
|
${{ matrix.pkg_prefix }}-ninja
|
||||||
|
${{ matrix.pkg_prefix }}-pkg-config
|
||||||
|
git
|
||||||
|
base-devel
|
||||||
|
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DVCPKG_INSTALL_OPTIONS="--allow-unsupported" \
|
||||||
|
-DOMATH_BUILD_TESTS=OFF \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cmake --build cmake-build/build/${{ matrix.preset }} --target omath
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
run: cmake --install cmake-build/build/${{ matrix.preset }} --prefix staging
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
shell: pwsh
|
||||||
|
run: Compress-Archive -Path staging\* -DestinationPath "${{ matrix.archive }}.zip"
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: gh release upload "${{ github.event.release.tag_name }}" "${{ matrix.archive }}.zip" --clobber
|
||||||
7
.idea/dictionaries/project.xml
generated
Normal file
7
.idea/dictionaries/project.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="project">
|
||||||
|
<words>
|
||||||
|
<w>vmprotect</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
@@ -31,6 +31,10 @@ option(OMATH_SUPRESS_SAFETY_CHECKS
|
|||||||
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
|
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
|
||||||
option(OMATH_ENABLE_FORCE_INLINE
|
option(OMATH_ENABLE_FORCE_INLINE
|
||||||
"Will for compiler to make some functions to be force inlined no matter what" ON)
|
"Will for compiler to make some functions to be force inlined no matter what" ON)
|
||||||
|
option(OMATH_VMPROTECT_INTEGRATION
|
||||||
|
"omath will use vmprotect sdk to protect sensitive parts of code from reverse engineering"
|
||||||
|
OFF)
|
||||||
|
|
||||||
if(VCPKG_MANIFEST_FEATURES)
|
if(VCPKG_MANIFEST_FEATURES)
|
||||||
foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
||||||
if(omath_feature STREQUAL "imgui")
|
if(omath_feature STREQUAL "imgui")
|
||||||
@@ -43,6 +47,8 @@ if(VCPKG_MANIFEST_FEATURES)
|
|||||||
set(OMATH_BUILD_BENCHMARK ON)
|
set(OMATH_BUILD_BENCHMARK ON)
|
||||||
elseif(omath_feature STREQUAL "examples")
|
elseif(omath_feature STREQUAL "examples")
|
||||||
set(OMATH_BUILD_EXAMPLES ON)
|
set(OMATH_BUILD_EXAMPLES ON)
|
||||||
|
elseif(omath_feature STREQUAL "vmprotect")
|
||||||
|
set(OMATH_VMPROTECT_INTEGRATION ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endforeach()
|
endforeach()
|
||||||
@@ -107,6 +113,11 @@ if(OMATH_IMGUI_INTEGRATION)
|
|||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(OMATH_VMPROTECT_INTEGRATION)
|
||||||
|
find_package(vmprotect_sdk CONFIG REQUIRED)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC vmprotect_sdk::vmprotect_sdk)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(OMATH_USE_AVX2)
|
if(OMATH_USE_AVX2)
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_AVX2)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_AVX2)
|
||||||
endif()
|
endif()
|
||||||
@@ -130,11 +141,10 @@ set_target_properties(
|
|||||||
CXX_STANDARD 23
|
CXX_STANDARD 23
|
||||||
CXX_STANDARD_REQUIRED ON)
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
if(OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY
|
||||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
|
"MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||||
)
|
endif()
|
||||||
endif ()
|
|
||||||
|
|
||||||
if(OMATH_USE_AVX2)
|
if(OMATH_USE_AVX2)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
|||||||
@@ -145,7 +145,7 @@
|
|||||||
"hidden": true,
|
"hidden": true,
|
||||||
"inherits": ["linux-base", "vcpkg-base"],
|
"inherits": ["linux-base", "vcpkg-base"],
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2"
|
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;vmprotect;examples"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
37
CODEOWNERS
Normal file
37
CODEOWNERS
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
## List of maintainers for the omath library
|
||||||
|
|
||||||
|
## This file purpose is to give newcomers to the project the responsible
|
||||||
|
## developers when submitting a pull request on GitHub, or opening a bug
|
||||||
|
## report in issues.
|
||||||
|
|
||||||
|
## This file will notably establish who is responsible for a specific
|
||||||
|
## area of omath. Being a maintainer means the following:
|
||||||
|
## - that person has good knownledge in the area
|
||||||
|
## - that person is able to enforce consistency in the area
|
||||||
|
## - that person may be available for giving help in the area
|
||||||
|
## - that person has push access on the repository
|
||||||
|
## Being a maintainer does not mean the following:
|
||||||
|
## - that person is dedicated to the area
|
||||||
|
## - that person is working full-time on the area/on omath
|
||||||
|
## - that person is paid
|
||||||
|
## - that person is always available
|
||||||
|
|
||||||
|
|
||||||
|
# omath core source code
|
||||||
|
/source @orange-cpp
|
||||||
|
/include @orange-cpp
|
||||||
|
|
||||||
|
# Tests and becnchmarks
|
||||||
|
/benchmark @orange-cpp
|
||||||
|
/tests @orange-cpp @luadebug
|
||||||
|
|
||||||
|
# Examples and documentation
|
||||||
|
/examples @luadebug @orange-cpp
|
||||||
|
/docs @orange-cpp
|
||||||
|
|
||||||
|
# Misc like formating
|
||||||
|
/scripts @luadebug
|
||||||
|
/pixi @luadebug
|
||||||
|
|
||||||
|
# CI/CD
|
||||||
|
/.github/workflows @luadbg @orange-cpp
|
||||||
42
INSTALL.md
42
INSTALL.md
@@ -1,6 +1,6 @@
|
|||||||
# 📥Installation Guide
|
# 📥Installation Guide
|
||||||
|
|
||||||
## <img width="28px" src="https://vcpkg.io/assets/mark/mark.svg" /> Using vcpkg
|
## <img width="28px" src="https://vcpkg.io/assets/mark/mark.svg" /> Using vcpkg (recomended)
|
||||||
**Note**: Support vcpkg for package management
|
**Note**: Support vcpkg for package management
|
||||||
1. Install [vcpkg](https://github.com/microsoft/vcpkg)
|
1. Install [vcpkg](https://github.com/microsoft/vcpkg)
|
||||||
2. Run the following command to install the orange-math package:
|
2. Run the following command to install the orange-math package:
|
||||||
@@ -28,6 +28,46 @@ target("...")
|
|||||||
add_packages("omath")
|
add_packages("omath")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## <img width="28px" src="https://github.githubassets.com/favicons/favicon.svg" /> Using prebuilt binaries (GitHub Releases)
|
||||||
|
|
||||||
|
**Note**: This is the fastest option if you don’t want to build from source.
|
||||||
|
|
||||||
|
1. **Go to the Releases page**
|
||||||
|
- Open the project’s GitHub **Releases** page and choose the latest version.
|
||||||
|
|
||||||
|
2. **Download the correct asset for your platform**
|
||||||
|
- Pick the archive that matches your OS and architecture (for example: Windows x64 / Linux x64 / macOS arm64).
|
||||||
|
|
||||||
|
3. **Extract the archive**
|
||||||
|
- You should end up with something like:
|
||||||
|
- `include/` (headers)
|
||||||
|
- `lib/` or `bin/` (library files / DLLs)
|
||||||
|
- sometimes `cmake/` (CMake package config)
|
||||||
|
|
||||||
|
4. **Use it in your project**
|
||||||
|
|
||||||
|
### Option A: CMake package (recommended if the release includes CMake config files)
|
||||||
|
If the extracted folder contains something like `lib/cmake/omath` or `cmake/omath`, you can point CMake to it:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
# Example: set this to the extracted prebuilt folder
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH "path/to/omath-prebuilt")
|
||||||
|
|
||||||
|
find_package(omath CONFIG REQUIRED)
|
||||||
|
target_link_libraries(main PRIVATE omath::omath)
|
||||||
|
```
|
||||||
|
### Option B: Manual include + link (works with any layout)
|
||||||
|
If there’s no CMake package config, link it manually:
|
||||||
|
```cmake
|
||||||
|
target_include_directories(main PRIVATE "path/to/omath-prebuilt/include")
|
||||||
|
|
||||||
|
# Choose ONE depending on what you downloaded:
|
||||||
|
# - Static library: .lib / .a
|
||||||
|
# - Shared library: .dll + .lib import (Windows), .so (Linux), .dylib (macOS)
|
||||||
|
|
||||||
|
target_link_directories(main PRIVATE "path/to/omath-prebuilt/lib")
|
||||||
|
target_link_libraries(main PRIVATE omath) # or the actual library filename
|
||||||
|
```
|
||||||
## <img width="28px" src="https://upload.wikimedia.org/wikipedia/commons/e/ef/CMake_logo.svg?" /> Build from source using CMake
|
## <img width="28px" src="https://upload.wikimedia.org/wikipedia/commons/e/ef/CMake_logo.svg?" /> Build from source using CMake
|
||||||
1. **Preparation**
|
1. **Preparation**
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,8 @@
|
|||||||
project(examples)
|
add_subdirectory(example_barycentric)
|
||||||
|
add_subdirectory(example_glfw3)
|
||||||
add_executable(example_projection_matrix_builder example_proj_mat_builder.cpp)
|
add_subdirectory(example_proj_mat_builder)
|
||||||
set_target_properties(
|
add_subdirectory(example_signature_scan)
|
||||||
example_projection_matrix_builder
|
add_subdirectory(exmple_var_encryption)
|
||||||
PROPERTIES CXX_STANDARD 23
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
|
||||||
target_link_libraries(example_projection_matrix_builder PRIVATE omath::omath)
|
|
||||||
|
|
||||||
add_executable(example_signature_scan example_signature_scan.cpp)
|
|
||||||
set_target_properties(
|
|
||||||
example_signature_scan
|
|
||||||
PROPERTIES CXX_STANDARD 23
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
|
||||||
target_link_libraries(example_signature_scan PRIVATE omath::omath)
|
|
||||||
|
|
||||||
add_executable(example_glfw3 example_glfw3.cpp)
|
|
||||||
set_target_properties(
|
|
||||||
example_glfw3
|
|
||||||
PROPERTIES CXX_STANDARD 23
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
|
||||||
|
|
||||||
find_package(OpenGL)
|
|
||||||
find_package(GLEW REQUIRED)
|
|
||||||
find_package(glfw3 CONFIG REQUIRED)
|
|
||||||
target_link_libraries(example_glfw3 PRIVATE omath::omath GLEW::GLEW glfw OpenGL::GL)
|
|
||||||
|
|
||||||
if(OMATH_ENABLE_VALGRIND)
|
if(OMATH_ENABLE_VALGRIND)
|
||||||
omath_setup_valgrind(example_projection_matrix_builder)
|
omath_setup_valgrind(example_projection_matrix_builder)
|
||||||
omath_setup_valgrind(example_signature_scan)
|
omath_setup_valgrind(example_signature_scan)
|
||||||
|
|||||||
14
examples/example_barycentric/CMakeLists.txt
Normal file
14
examples/example_barycentric/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
project(example_barycentric)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} example_barycentric.cpp)
|
||||||
|
set_target_properties(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PROPERTIES CXX_STANDARD 23
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
|
find_package(OpenGL)
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath GLEW::GLEW glfw OpenGL::GL)
|
||||||
427
examples/example_barycentric/example_barycentric.cpp
Normal file
427
examples/example_barycentric/example_barycentric.cpp
Normal file
@@ -0,0 +1,427 @@
|
|||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
#include <omath/omath.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using omath::Color;
|
||||||
|
using omath::Triangle;
|
||||||
|
using omath::Vector3;
|
||||||
|
|
||||||
|
static const char* vertexShaderSource = R"(
|
||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aColor;
|
||||||
|
layout (location = 2) in float aPointSize;
|
||||||
|
layout (location = 3) in float aIsLine;
|
||||||
|
|
||||||
|
out vec3 vColor;
|
||||||
|
out float vIsLine;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(aPos, 1.0);
|
||||||
|
vColor = aColor;
|
||||||
|
gl_PointSize = aPointSize;
|
||||||
|
vIsLine = aIsLine;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
static const char* fragmentShaderSource = R"(
|
||||||
|
#version 330 core
|
||||||
|
in vec3 vColor;
|
||||||
|
in float vIsLine;
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
if (vIsLine < 0.5) {
|
||||||
|
// Calculate distance from center of the point
|
||||||
|
vec2 coord = gl_PointCoord - vec2(0.5);
|
||||||
|
if(length(coord) > 0.5)
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
FragColor = vec4(vColor, 1.0);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
GLuint compileShader(GLenum type, const char* src)
|
||||||
|
{
|
||||||
|
GLuint shader = glCreateShader(type);
|
||||||
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
|
glCompileShader(shader);
|
||||||
|
GLint ok;
|
||||||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
char log[1024];
|
||||||
|
glGetShaderInfoLog(shader, sizeof(log), nullptr, log);
|
||||||
|
std::cerr << "Shader error: " << log << std::endl;
|
||||||
|
}
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawChar(char c, float x, float y, float scale, const Color& color, std::vector<float>& lines)
|
||||||
|
{
|
||||||
|
float w = 0.5f * scale;
|
||||||
|
float h = 1.0f * scale;
|
||||||
|
|
||||||
|
auto add = [&](float x1, float y1, float x2, float y2)
|
||||||
|
{
|
||||||
|
lines.push_back(x + x1 * w);
|
||||||
|
lines.push_back(y + y1 * h);
|
||||||
|
lines.push_back(0.0f);
|
||||||
|
lines.push_back(color.x);
|
||||||
|
lines.push_back(color.y);
|
||||||
|
lines.push_back(color.z);
|
||||||
|
lines.push_back(1.0f); // size
|
||||||
|
lines.push_back(1.0f); // isLine
|
||||||
|
|
||||||
|
lines.push_back(x + x2 * w);
|
||||||
|
lines.push_back(y + y2 * h);
|
||||||
|
lines.push_back(0.0f);
|
||||||
|
lines.push_back(color.x);
|
||||||
|
lines.push_back(color.y);
|
||||||
|
lines.push_back(color.z);
|
||||||
|
lines.push_back(1.0f); // size
|
||||||
|
lines.push_back(1.0f); // isLine
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '0':
|
||||||
|
add(0, 0, 1, 0);
|
||||||
|
add(1, 0, 1, 1);
|
||||||
|
add(1, 1, 0, 1);
|
||||||
|
add(0, 1, 0, 0);
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
add(0.5f, 0, 0.5f, 1);
|
||||||
|
add(0.25f, 0.75f, 0.5f, 1);
|
||||||
|
add(0.25f, 0, 0.75f, 0);
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
add(0, 1, 1, 1);
|
||||||
|
add(1, 1, 1, 0.5f);
|
||||||
|
add(1, 0.5f, 0, 0.5f);
|
||||||
|
add(0, 0.5f, 0, 0);
|
||||||
|
add(0, 0, 1, 0);
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
add(0, 1, 1, 1);
|
||||||
|
add(1, 1, 1, 0);
|
||||||
|
add(1, 0, 0, 0);
|
||||||
|
add(0, 0.5f, 1, 0.5f);
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
add(0, 1, 0, 0.5f);
|
||||||
|
add(0, 0.5f, 1, 0.5f);
|
||||||
|
add(1, 1, 1, 0);
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
add(1, 1, 0, 1);
|
||||||
|
add(0, 1, 0, 0.5f);
|
||||||
|
add(0, 0.5f, 1, 0.5f);
|
||||||
|
add(1, 0.5f, 1, 0);
|
||||||
|
add(1, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
add(1, 1, 0, 1);
|
||||||
|
add(0, 1, 0, 0);
|
||||||
|
add(0, 0, 1, 0);
|
||||||
|
add(1, 0, 1, 0.5f);
|
||||||
|
add(1, 0.5f, 0, 0.5f);
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
add(0, 1, 1, 1);
|
||||||
|
add(1, 1, 0.5f, 0);
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
add(0, 0, 1, 0);
|
||||||
|
add(1, 0, 1, 1);
|
||||||
|
add(1, 1, 0, 1);
|
||||||
|
add(0, 1, 0, 0);
|
||||||
|
add(0, 0.5f, 1, 0.5f);
|
||||||
|
break;
|
||||||
|
case '9':
|
||||||
|
add(1, 0.5f, 0, 0.5f);
|
||||||
|
add(0, 0.5f, 0, 1);
|
||||||
|
add(0, 1, 1, 1);
|
||||||
|
add(1, 1, 1, 0);
|
||||||
|
add(1, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
add(0.4f, 0, 0.6f, 0);
|
||||||
|
add(0.6f, 0, 0.6f, 0.2f);
|
||||||
|
add(0.6f, 0.2f, 0.4f, 0.2f);
|
||||||
|
add(0.4f, 0.2f, 0.4f, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawText(const std::string& text, float x, float y, float scale, const Color& color, std::vector<float>& lines)
|
||||||
|
{
|
||||||
|
float cursor = x;
|
||||||
|
for (char c : text)
|
||||||
|
{
|
||||||
|
drawChar(c, cursor, y, scale, color, lines);
|
||||||
|
cursor += (c == '.' ? 0.3f : 0.7f) * scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GLFWwindow* initWindow(int width, int height, const char* title)
|
||||||
|
{
|
||||||
|
if (!glfwInit())
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to initialize GLFW\n";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
|
GLFWwindow* window = glfwCreateWindow(width, height, title, NULL, NULL);
|
||||||
|
if (!window)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to create GLFW window\n";
|
||||||
|
glfwTerminate();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// Check if context is valid using standard GL
|
||||||
|
const GLubyte* renderer = glGetString(GL_RENDERER);
|
||||||
|
const GLubyte* version = glGetString(GL_VERSION);
|
||||||
|
if (renderer && version)
|
||||||
|
{
|
||||||
|
std::cout << "Renderer: " << renderer << "\n";
|
||||||
|
std::cout << "OpenGL version supported: " << version << "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to get GL_RENDERER or GL_VERSION. Context might be invalid.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
glewExperimental = GL_TRUE;
|
||||||
|
GLenum glewErr = glewInit();
|
||||||
|
if (glewErr != GLEW_OK)
|
||||||
|
{
|
||||||
|
// Ignore GLEW_ERROR_NO_GLX_DISPLAY if we have a valid context (e.g. Wayland)
|
||||||
|
if (glewErr == GLEW_ERROR_NO_GLX_DISPLAY && renderer)
|
||||||
|
{
|
||||||
|
std::cerr << "GLEW warning: " << glewGetErrorString(glewErr) << " (Ignored because context seems valid)\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to initialize GLEW: " << glewGetErrorString(glewErr) << "\n";
|
||||||
|
glfwTerminate();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint createShaderProgram()
|
||||||
|
{
|
||||||
|
GLuint vs = compileShader(GL_VERTEX_SHADER, vertexShaderSource);
|
||||||
|
GLuint fs = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
|
||||||
|
GLuint shaderProgram = glCreateProgram();
|
||||||
|
glAttachShader(shaderProgram, vs);
|
||||||
|
glAttachShader(shaderProgram, fs);
|
||||||
|
glLinkProgram(shaderProgram);
|
||||||
|
return shaderProgram;
|
||||||
|
}
|
||||||
|
|
||||||
|
void generatePointCloud(std::vector<float>& pointCloud, const Triangle<Vector3<float>>& triangle)
|
||||||
|
{
|
||||||
|
const auto& A = triangle.m_vertex1;
|
||||||
|
const auto& B = triangle.m_vertex2;
|
||||||
|
const auto& C = triangle.m_vertex3;
|
||||||
|
// Iterating over barycentric coordinates (u, v, w) from 0.0 to 1.0
|
||||||
|
for (float u = 0.0f; u <= 1.0f; u += 0.015f)
|
||||||
|
{
|
||||||
|
for (float v = 0.0f; v <= 1.0f - u; v += 0.015f)
|
||||||
|
{
|
||||||
|
float w = 1.0f - u - v;
|
||||||
|
if (w >= 0.0f && w <= 1.0f)
|
||||||
|
{
|
||||||
|
Vector3<float> P = A * u + B * v + C * w;
|
||||||
|
pointCloud.push_back(P.x);
|
||||||
|
pointCloud.push_back(P.y);
|
||||||
|
pointCloud.push_back(P.z);
|
||||||
|
pointCloud.push_back(u);
|
||||||
|
pointCloud.push_back(v);
|
||||||
|
pointCloud.push_back(w);
|
||||||
|
pointCloud.push_back(2.0f); // size
|
||||||
|
pointCloud.push_back(0.0f); // isLine
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupBuffers(GLuint& VAO_cloud, GLuint& VBO_cloud, const std::vector<float>& pointCloud, GLuint& VAO_dyn,
|
||||||
|
GLuint& VBO_dyn)
|
||||||
|
{
|
||||||
|
glGenVertexArrays(1, &VAO_cloud);
|
||||||
|
glGenBuffers(1, &VBO_cloud);
|
||||||
|
glBindVertexArray(VAO_cloud);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO_cloud);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, pointCloud.size() * sizeof(float), pointCloud.data(), GL_STATIC_DRAW);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(7 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(3);
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &VAO_dyn);
|
||||||
|
glGenBuffers(1, &VBO_dyn);
|
||||||
|
glBindVertexArray(VAO_dyn);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO_dyn);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, 1000 * 8 * sizeof(float), NULL, GL_DYNAMIC_DRAW);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(7 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateDynamicData(std::vector<float>& dynData, float u, float v, float w, const Vector3<float>& P,
|
||||||
|
const Triangle<Vector3<float>>& triangle)
|
||||||
|
{
|
||||||
|
const auto& A = triangle.m_vertex1;
|
||||||
|
const auto& B = triangle.m_vertex2;
|
||||||
|
const auto& C = triangle.m_vertex3;
|
||||||
|
|
||||||
|
float sizeA = 10.0f + u * 30.0f;
|
||||||
|
float sizeB = 10.0f + v * 30.0f;
|
||||||
|
float sizeC = 10.0f + w * 30.0f;
|
||||||
|
float sizeP = 12.0f;
|
||||||
|
|
||||||
|
dynData = {// Lines from P to A, B, C
|
||||||
|
P.x, P.y, P.z, u, v, w, 1.0f, 1.0f, A.x, A.y, A.z, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||||
|
|
||||||
|
P.x, P.y, P.z, u, v, w, 1.0f, 1.0f, B.x, B.y, B.z, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
||||||
|
|
||||||
|
P.x, P.y, P.z, u, v, w, 1.0f, 1.0f, C.x, C.y, C.z, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||||
|
|
||||||
|
// The animated dot itself (White)
|
||||||
|
P.x, P.y, P.z, 1.0f, 1.0f, 1.0f, sizeP, 0.0f,
|
||||||
|
|
||||||
|
// The 3 corner dots
|
||||||
|
A.x, A.y, A.z, 1.0f, 0.0f, 0.0f, sizeA, 0.0f, B.x, B.y, B.z, 0.0f, 1.0f, 0.0f, sizeB, 0.0f, C.x, C.y,
|
||||||
|
C.z, 0.0f, 0.0f, 1.0f, sizeC, 0.0f};
|
||||||
|
|
||||||
|
char bufA[16], bufB[16], bufC[16];
|
||||||
|
snprintf(bufA, sizeof(bufA), "%.2f", u);
|
||||||
|
snprintf(bufB, sizeof(bufB), "%.2f", v);
|
||||||
|
snprintf(bufC, sizeof(bufC), "%.2f", w);
|
||||||
|
|
||||||
|
// Keep text at a fixed distance from the dots
|
||||||
|
float distA = 0.13f;
|
||||||
|
float distB = 0.13f;
|
||||||
|
float distC = 0.13f;
|
||||||
|
|
||||||
|
drawText(bufA, A.x - 0.05f, A.y + distA, 0.1f, Color(1, 0, 0, 1), dynData);
|
||||||
|
drawText(bufB, B.x - 0.15f - distB, B.y - 0.05f - distB, 0.1f, Color(0, 1, 0, 1), dynData);
|
||||||
|
drawText(bufC, C.x + 0.05f + distC, C.y - 0.05f - distC, 0.1f, Color(0, 0, 1, 1), dynData);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
GLFWwindow* window = initWindow(800, 800, "Barycentric Coordinates");
|
||||||
|
if (!window)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
GLuint shaderProgram = createShaderProgram();
|
||||||
|
|
||||||
|
// Triangle vertices as shown in the picture (Red, Green, Blue)
|
||||||
|
// Scaled down slightly to leave room for text
|
||||||
|
Triangle<Vector3<float>> triangle(Vector3<float>(0.0f, 0.6f, 0.0f), // Red dot (top)
|
||||||
|
Vector3<float>(-0.6f, -0.6f, 0.0f), // Green dot (bottom left)
|
||||||
|
Vector3<float>(0.6f, -0.6f, 0.0f) // Blue dot (bottom right)
|
||||||
|
);
|
||||||
|
|
||||||
|
std::vector<float> pointCloud;
|
||||||
|
generatePointCloud(pointCloud, triangle);
|
||||||
|
|
||||||
|
GLuint VAO_cloud, VBO_cloud, VAO_dyn, VBO_dyn;
|
||||||
|
setupBuffers(VAO_cloud, VBO_cloud, pointCloud, VAO_dyn, VBO_dyn);
|
||||||
|
|
||||||
|
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
while (!glfwWindowShouldClose(window))
|
||||||
|
{
|
||||||
|
glClearColor(0.02f, 0.02f, 0.02f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
|
// Draw the point cloud (the iterated points)
|
||||||
|
glBindVertexArray(VAO_cloud);
|
||||||
|
glDrawArrays(GL_POINTS, 0, pointCloud.size() / 8);
|
||||||
|
|
||||||
|
// Animate the white dot to simulate dragging
|
||||||
|
float t = glfwGetTime();
|
||||||
|
float u = (std::sin(t * 1.5f) * 0.5f + 0.5f);
|
||||||
|
float v = (std::cos(t * 1.1f) * 0.5f + 0.5f);
|
||||||
|
|
||||||
|
if (u + v > 1.0f)
|
||||||
|
{
|
||||||
|
u = 1.0f - u;
|
||||||
|
v = 1.0f - v;
|
||||||
|
}
|
||||||
|
float w = 1.0f - u - v;
|
||||||
|
|
||||||
|
if (w > 1.0f)
|
||||||
|
{
|
||||||
|
float diff = w - 1.0f;
|
||||||
|
w = 1.0f;
|
||||||
|
u += diff / 2.0f;
|
||||||
|
v += diff / 2.0f;
|
||||||
|
}
|
||||||
|
else if (w < 0.0f)
|
||||||
|
{
|
||||||
|
float diff = -w;
|
||||||
|
w = 0.0f;
|
||||||
|
u -= diff / 2.0f;
|
||||||
|
v -= diff / 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3<float> P = triangle.m_vertex1 * u + triangle.m_vertex2 * v + triangle.m_vertex3 * w;
|
||||||
|
|
||||||
|
std::vector<float> dynData;
|
||||||
|
updateDynamicData(dynData, u, v, w, P, triangle);
|
||||||
|
|
||||||
|
glBindVertexArray(VAO_dyn);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO_dyn);
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, dynData.size() * sizeof(float), dynData.data());
|
||||||
|
|
||||||
|
// Draw lines
|
||||||
|
glDrawArrays(GL_LINES, 0, 6);
|
||||||
|
|
||||||
|
// Draw text lines
|
||||||
|
int numTextVertices = (dynData.size() / 8) - 10;
|
||||||
|
if (numTextVertices > 0)
|
||||||
|
{
|
||||||
|
glDrawArrays(GL_LINES, 10, numTextVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw dots
|
||||||
|
glDrawArrays(GL_POINTS, 6, 4);
|
||||||
|
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
14
examples/example_glfw3/CMakeLists.txt
Normal file
14
examples/example_glfw3/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
project(example_glfw3)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} example_glfw3.cpp)
|
||||||
|
set_target_properties(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PROPERTIES CXX_STANDARD 23
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
|
find_package(OpenGL)
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath GLEW::GLEW glfw OpenGL::GL)
|
||||||
@@ -342,7 +342,7 @@ int main()
|
|||||||
old_mouse_time = glfwGetTime();
|
old_mouse_time = glfwGetTime();
|
||||||
mouse_capture = !mouse_capture;
|
mouse_capture = !mouse_capture;
|
||||||
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, mouse_capture ? GLFW_CURSOR_CAPTURED : GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR, mouse_capture ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
||||||
}
|
}
|
||||||
if (mouse_capture)
|
if (mouse_capture)
|
||||||
{
|
{
|
||||||
10
examples/example_proj_mat_builder/CMakeLists.txt
Normal file
10
examples/example_proj_mat_builder/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
project(example_projection_matrix_builder)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} example_proj_mat_builder.cpp)
|
||||||
|
set_target_properties(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PROPERTIES CXX_STANDARD 23
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath)
|
||||||
10
examples/example_signature_scan/CMakeLists.txt
Normal file
10
examples/example_signature_scan/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
project(example_signature_scan)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} example_signature_scan.cpp)
|
||||||
|
set_target_properties(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PROPERTIES CXX_STANDARD 23
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath)
|
||||||
10
examples/exmple_var_encryption/CMakeLists.txt
Normal file
10
examples/exmple_var_encryption/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
project(example_var_encryption)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} main.cpp)
|
||||||
|
set_target_properties(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PROPERTIES CXX_STANDARD 23
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath)
|
||||||
15
examples/exmple_var_encryption/main.cpp
Normal file
15
examples/exmple_var_encryption/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// Created by orange on 24.02.2026.
|
||||||
|
//
|
||||||
|
#include "omath/containers/encrypted_variable.hpp"
|
||||||
|
#include <omath/omath.hpp>
|
||||||
|
#include <print>
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
OMATH_DEF_CRYPT_VAR(int, 64) var{5};
|
||||||
|
var.encrypt();
|
||||||
|
std::println("{}", var.value());
|
||||||
|
var.decrypt();
|
||||||
|
std::println("{}", var.value());
|
||||||
|
return var.value();
|
||||||
|
}
|
||||||
@@ -2,10 +2,14 @@
|
|||||||
// Created by Vladislav on 04.01.2026.
|
// Created by Vladislav on 04.01.2026.
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <VMProtectSDK.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#include <source_location>
|
||||||
|
|
||||||
|
|
||||||
#ifdef OMATH_ENABLE_FORCE_INLINE
|
#ifdef OMATH_ENABLE_FORCE_INLINE
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define OMATH_FORCE_INLINE __forceinline
|
#define OMATH_FORCE_INLINE __forceinline
|
||||||
@@ -62,20 +66,13 @@ namespace omath::detail
|
|||||||
return splitmix64(base_seed() + 0xD1B54A32D192ED03ull * (Stream + 1));
|
return splitmix64(base_seed() + 0xD1B54A32D192ED03ull * (Stream + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
consteval std::uint64_t bounded_u64(const std::uint64_t x, const std::uint64_t bound)
|
|
||||||
{
|
|
||||||
return (x * bound) >> 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::int64_t Lo, std::int64_t Hi, std::uint64_t Stream>
|
template<std::int64_t Lo, std::int64_t Hi, std::uint64_t Stream>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
consteval std::int64_t rand_uint8_t()
|
consteval std::int64_t rand_uint8_t()
|
||||||
{
|
{
|
||||||
static_assert(Lo <= Hi);
|
static_assert(Lo <= Hi);
|
||||||
const std::uint64_t span = static_cast<std::uint64_t>(Hi - Lo) + 1ull;
|
|
||||||
const std::uint64_t r = rand_u64<Stream>();
|
const std::uint64_t r = rand_u64<Stream>();
|
||||||
return static_cast<std::int64_t>(bounded_u64(r, span)) + Lo;
|
return static_cast<std::int64_t>(r) + Lo;
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
consteval std::uint64_t rand_u64(const std::uint64_t seed, const std::uint64_t i)
|
consteval std::uint64_t rand_u64(const std::uint64_t seed, const std::uint64_t i)
|
||||||
@@ -117,16 +114,18 @@ namespace omath
|
|||||||
bool m_is_encrypted{};
|
bool m_is_encrypted{};
|
||||||
value_type m_data{};
|
value_type m_data{};
|
||||||
|
|
||||||
OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key()
|
OMATH_FORCE_INLINE void xor_contained_var_by_key()
|
||||||
{
|
{
|
||||||
|
VMProtectBeginVirtualization(nullptr);
|
||||||
// Safe, keeps const-correctness, and avoids reinterpret_cast issues
|
// Safe, keeps const-correctness, and avoids reinterpret_cast issues
|
||||||
auto bytes = std::as_writable_bytes(std::span<value_type, 1>{&m_data, 1});
|
auto bytes = std::as_writable_bytes(std::span<value_type, 1>{&m_data, 1});
|
||||||
|
|
||||||
for (std::size_t i = 0; i < bytes.size(); ++i)
|
for (std::size_t i = 0; i < bytes.size(); ++i)
|
||||||
{
|
{
|
||||||
const std::uint8_t k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
const auto k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
||||||
bytes[i] ^= static_cast<std::byte>(k);
|
bytes[i] ^= static_cast<std::byte>(k);
|
||||||
}
|
}
|
||||||
|
VMProtectEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -141,7 +140,7 @@ namespace omath
|
|||||||
return m_is_encrypted;
|
return m_is_encrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_FORCE_INLINE constexpr void decrypt()
|
OMATH_FORCE_INLINE void decrypt()
|
||||||
{
|
{
|
||||||
if (!m_is_encrypted)
|
if (!m_is_encrypted)
|
||||||
return;
|
return;
|
||||||
@@ -149,7 +148,7 @@ namespace omath
|
|||||||
m_is_encrypted = false;
|
m_is_encrypted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_FORCE_INLINE constexpr void encrypt()
|
OMATH_FORCE_INLINE void encrypt()
|
||||||
{
|
{
|
||||||
if (m_is_encrypted)
|
if (m_is_encrypted)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ endif()
|
|||||||
set(EXAMPLES_BIN_DIR "${PROJECT_ROOT}/out/${CMAKE_BUILD_TYPE}")
|
set(EXAMPLES_BIN_DIR "${PROJECT_ROOT}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
if(NOT EXISTS "${EXAMPLES_BIN_DIR}")
|
if(NOT EXISTS "${EXAMPLES_BIN_DIR}")
|
||||||
message(FATAL_ERROR "Examples binary directory not found: ${EXAMPLES_BIN_DIR}. Please build the project first.")
|
message(
|
||||||
|
FATAL_ERROR
|
||||||
|
"Examples binary directory not found: ${EXAMPLES_BIN_DIR}. Please build the project first."
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Looking for benchmark executables in: ${EXAMPLES_BIN_DIR}")
|
message(STATUS "Looking for benchmark executables in: ${EXAMPLES_BIN_DIR}")
|
||||||
@@ -43,16 +46,13 @@ foreach(EXAMPLE_PATH ${EXAMPLE_FILES})
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# On Linux/macOS, check permissions or just try to run it.
|
# On Linux/macOS, check permissions or just try to run it.
|
||||||
|
|
||||||
message(STATUS "-------------------------------------------------")
|
message(STATUS "-------------------------------------------------")
|
||||||
message(STATUS "Running benchmark: ${FILENAME}")
|
message(STATUS "Running benchmark: ${FILENAME}")
|
||||||
message(STATUS "-------------------------------------------------")
|
message(STATUS "-------------------------------------------------")
|
||||||
|
|
||||||
execute_process(
|
execute_process(COMMAND "${EXAMPLE_PATH}" WORKING_DIRECTORY "${PROJECT_ROOT}"
|
||||||
COMMAND "${EXAMPLE_PATH}"
|
RESULT_VARIABLE EXIT_CODE)
|
||||||
WORKING_DIRECTORY "${PROJECT_ROOT}"
|
|
||||||
RESULT_VARIABLE EXIT_CODE
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT EXIT_CODE EQUAL 0)
|
if(NOT EXIT_CODE EQUAL 0)
|
||||||
message(WARNING "Benchmark ${FILENAME} exited with error code: ${EXIT_CODE}")
|
message(WARNING "Benchmark ${FILENAME} exited with error code: ${EXIT_CODE}")
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ endif()
|
|||||||
set(EXAMPLES_BIN_DIR "${PROJECT_ROOT}/out/${CMAKE_BUILD_TYPE}")
|
set(EXAMPLES_BIN_DIR "${PROJECT_ROOT}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
if(NOT EXISTS "${EXAMPLES_BIN_DIR}")
|
if(NOT EXISTS "${EXAMPLES_BIN_DIR}")
|
||||||
message(FATAL_ERROR "Examples binary directory not found: ${EXAMPLES_BIN_DIR}. Please build the project first.")
|
message(
|
||||||
|
FATAL_ERROR
|
||||||
|
"Examples binary directory not found: ${EXAMPLES_BIN_DIR}. Please build the project first."
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Looking for example executables in: ${EXAMPLES_BIN_DIR}")
|
message(STATUS "Looking for example executables in: ${EXAMPLES_BIN_DIR}")
|
||||||
@@ -43,16 +46,13 @@ foreach(EXAMPLE_PATH ${EXAMPLE_FILES})
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# On Linux/macOS, check permissions or just try to run it.
|
# On Linux/macOS, check permissions or just try to run it.
|
||||||
|
|
||||||
message(STATUS "-------------------------------------------------")
|
message(STATUS "-------------------------------------------------")
|
||||||
message(STATUS "Running example: ${FILENAME}")
|
message(STATUS "Running example: ${FILENAME}")
|
||||||
message(STATUS "-------------------------------------------------")
|
message(STATUS "-------------------------------------------------")
|
||||||
|
|
||||||
execute_process(
|
execute_process(COMMAND "${EXAMPLE_PATH}" WORKING_DIRECTORY "${PROJECT_ROOT}"
|
||||||
COMMAND "${EXAMPLE_PATH}"
|
RESULT_VARIABLE EXIT_CODE)
|
||||||
WORKING_DIRECTORY "${PROJECT_ROOT}"
|
|
||||||
RESULT_VARIABLE EXIT_CODE
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT EXIT_CODE EQUAL 0)
|
if(NOT EXIT_CODE EQUAL 0)
|
||||||
message(WARNING "Example ${FILENAME} exited with error code: ${EXIT_CODE}")
|
message(WARNING "Example ${FILENAME} exited with error code: ${EXIT_CODE}")
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ endif()
|
|||||||
set(EXAMPLES_BIN_DIR "${PROJECT_ROOT}/out/${CMAKE_BUILD_TYPE}")
|
set(EXAMPLES_BIN_DIR "${PROJECT_ROOT}/out/${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
if(NOT EXISTS "${EXAMPLES_BIN_DIR}")
|
if(NOT EXISTS "${EXAMPLES_BIN_DIR}")
|
||||||
message(FATAL_ERROR "Examples binary directory not found: ${EXAMPLES_BIN_DIR}. Please build the project first.")
|
message(
|
||||||
|
FATAL_ERROR
|
||||||
|
"Examples binary directory not found: ${EXAMPLES_BIN_DIR}. Please build the project first."
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Looking for unit test executables in: ${EXAMPLES_BIN_DIR}")
|
message(STATUS "Looking for unit test executables in: ${EXAMPLES_BIN_DIR}")
|
||||||
@@ -43,16 +46,13 @@ foreach(EXAMPLE_PATH ${EXAMPLE_FILES})
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# On Linux/macOS, check permissions or just try to run it.
|
# On Linux/macOS, check permissions or just try to run it.
|
||||||
|
|
||||||
message(STATUS "-------------------------------------------------")
|
message(STATUS "-------------------------------------------------")
|
||||||
message(STATUS "Running unit_tests: ${FILENAME}")
|
message(STATUS "Running unit_tests: ${FILENAME}")
|
||||||
message(STATUS "-------------------------------------------------")
|
message(STATUS "-------------------------------------------------")
|
||||||
|
|
||||||
execute_process(
|
execute_process(COMMAND "${EXAMPLE_PATH}" WORKING_DIRECTORY "${PROJECT_ROOT}"
|
||||||
COMMAND "${EXAMPLE_PATH}"
|
RESULT_VARIABLE EXIT_CODE)
|
||||||
WORKING_DIRECTORY "${PROJECT_ROOT}"
|
|
||||||
RESULT_VARIABLE EXIT_CODE
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT EXIT_CODE EQUAL 0)
|
if(NOT EXIT_CODE EQUAL 0)
|
||||||
message(WARNING "Example ${FILENAME} exited with error code: ${EXIT_CODE}")
|
message(WARNING "Example ${FILENAME} exited with error code: ${EXIT_CODE}")
|
||||||
|
|||||||
15
scripts/cmake-format.sh
Normal file
15
scripts/cmake-format.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Format all CMakeLists.txt and *.cmake files in the repo (excluding common build dirs)
|
||||||
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
find . \
|
||||||
|
-path "./build" -prune -o \
|
||||||
|
-path "./cmake-build*" -prune -o \
|
||||||
|
-path "./out" -prune -o \
|
||||||
|
-path "./.git" -prune -o \
|
||||||
|
\( -name "CMakeLists.txt" -o -name "*.cmake" \) -print0 \
|
||||||
|
| xargs -0 cmake-format -i
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <VMProtectSDK.h>
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"default-registry": {
|
"default-registry": {
|
||||||
"kind": "git",
|
"kind": "git",
|
||||||
"baseline": "b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01",
|
"baseline": "05442024c3fda64320bd25d2251cc9807b84fb6f",
|
||||||
"repository": "https://github.com/microsoft/vcpkg"
|
"repository": "https://github.com/microsoft/vcpkg"
|
||||||
},
|
},
|
||||||
"registries": [
|
"registries": [
|
||||||
|
|||||||
11
vcpkg.json
11
vcpkg.json
@@ -17,9 +17,16 @@
|
|||||||
],
|
],
|
||||||
"features": {
|
"features": {
|
||||||
"avx2": {
|
"avx2": {
|
||||||
"description": "Omath will use AVX2 to boost performance",
|
"description": "omath will use AVX2 to boost performance",
|
||||||
"supports": "!arm"
|
"supports": "!arm"
|
||||||
},
|
},
|
||||||
|
"vmprotect": {
|
||||||
|
"description": "omath will use vmprotect sdk to protect sensitive parts of code from reverse engineering",
|
||||||
|
"supports": "windows | linux | osx | android",
|
||||||
|
"dependencies": [
|
||||||
|
"orange-vmprotect-sdk"
|
||||||
|
]
|
||||||
|
},
|
||||||
"benchmark": {
|
"benchmark": {
|
||||||
"description": "Build benchmarks",
|
"description": "Build benchmarks",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@@ -35,7 +42,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"imgui": {
|
"imgui": {
|
||||||
"description": "Omath will define method to convert omath types to imgui types",
|
"description": "omath will define method to convert omath types to imgui types",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"imgui"
|
"imgui"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user