Skip to content

pocper/computer-graphics

Repository files navigation

computer-graphics

這倉儲包含了從基礎圖形界面到進階 OpenGL 渲染的多個實驗專案,涵蓋了 winBGIm、SFML 以及現代 OpenGL 的應用。

專案列表 (Projects)

  1. 01_winBGIm_DVD
    • 使用 winBGIm 實現經典的DVD標誌碰撞反彈模擬
  2. 02_winBGIm_Snake
    • 使用 winBGIm 採用 遺傳演算法 (GA) 與線性回歸 (LR) 訓練的 AI 貪食蛇
    • 狀態:開發中,目前模型尚未完全收斂
  3. 03_SFML_Snake
    • 使用 SFML框架 重製 02_winBGIm_Snake 的 AI 貪食蛇遊戲
  4. 04_openGL_playground
    • 使用 OpenGL 基礎開發的 3D 渲染環境,包含木箱渲染與自由移動相機
  5. 05_openGL_robot
    • 機器人控制系統,整合模型載入、 ImGui UI 界面與16軸關節根據使用者拖拉角度顯示實時模型姿勢
    • 注意:由於 model_Robot 3D 模型非本人原創,基於版權考量,本倉儲不提供模型檔案
  6. 06_openGL_car
    • 車載機械手臂控制系統,整合模型載入、 ImGui UI 界面與4軸關節根據使用者拖拉角度顯示實時模型姿勢
    • 注意:由於 model_Robot 3D 模型非本人原創,基於版權考量,本倉儲不提供模型檔案

成果展示 (Screenshots)

01_winBGIm_DVD
經典 DVD 標誌碰撞模擬

02 & 03_AI_Snake
遺傳演算法與類神經網路訓練展示

04_openGL_playground
3D 渲染環境與自由移動相機

05_openGL_robot
機器人控制系統

06_openGL_car
車子控制系統


環境建置 (Prerequisite)

本專案主要使用 MinGW-w64 (winlibs) 工具鏈、makefileNinja 進行編譯

1. 安裝編譯器 MinGW (適用於 Project 01, 02, 04)

建議下載 winlibs MinGW (UCRT 版本),內含 GCC、Make 與 Ninja

curl -L -O https://github.com/brechtsanders/winlibs_mingw/releases/download/15.2.0posix-14.0.0-ucrt-r7/winlibs-x86_64-posix-seh-gcc-15.2.0-mingw-w64ucrt-14.0.0-r7.zip

注意: 下載後請解壓縮並將 bin 目錄加入系統的環境變數 PATH 中。

2. Visual Studio 環境 (適用於 Project 03, 05, 06)

  • 需安裝 Visual Studio 2022 或更高版本
  • 安裝時請勾選 「使用 C++ 的桌面開發」 (Desktop development with C++),以取得 MSVC 編譯器、Windows SDK 及 CMake 工具

3. Python 3 (用於 GLAD 套件編譯)

GLAD 需要 Python 環境來生成 OpenGL 載入器。

  • 快速安裝:開啟 PowerShell 並輸入:
    winget install Python.Python.3
  • 手動安裝:前往 Python 官網 下載安裝檔。
  • 重要設定:安裝時請務必勾選 "Add Python to PATH",否則無法在終端機直接執行 pippython 指令。

🖥️ 測試環境版本 (Tested Environment)

本專案已在以下環境測試通過,建議使用相同或更高版本:

工具 測試版本 備註
Operating System Windows 11 (64-bit) -
MinGW-w64 GCC 15.2.0 (winlibs) 支援最新 C++ 標準
Visual Studio VS 2022 (v17.14.7) 用於 Project 03, 05, 06
Python 3.12.2 用於 GLAD2 生成器

依賴庫安裝 (Library Setup)

請先在專案根目錄建立 lib 資料夾,所有的第三方庫將存放於此:

mkdir -p ./lib

圖形框架 (Graphics Frameworks)

  • winBGIm64 (01_winBGIm_DVD/02_winBGIm_Snake)

    github - winBGIm64

    cd computer-graphics/lib
    git clone https://github.com/ki9gpin/WinBGIm-64
    cd WinBGIm-64
    cmake -G Ninja
    cmake --build .
  • SFML (03_SFML_Snake)

    github - SFML

    cd computer-graphics/lib
    curl -L -O https://github.com/SFML/SFML/releases/download/3.0.2/SFML-3.0.2-Windows.MinGW.x64.zip
    tar -xf SFML-3.0.2-Windows.MinGW.x64.zip

openGL 核心工具與數學庫

  • GLAD

    github - GLAD

    cd computer-graphics/lib
    pip install glad2
    python -m glad --api "gl:core=3.3" --extensions "" --out-path ./glad c --loader
  • GLFW

    github - GLFW

    cd computer-graphics/lib
    curl -L -O https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.bin.WIN64.zip
    tar -xf glfw-3.4.bin.WIN64.zip
  • Eigen

    github - Eigen

    cd computer-graphics/lib
    git clone https://gitlab.com/libeigen/eigen.git
  • GLM

    github - GLM

    cd computer-graphics/lib
    git clone https://github.com/g-truc/glm.git
    cd glm
    cmake -G Ninja -DGLM_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -B build .
    cmake --build build -- all

模型載入

  • Assimp

    github - Assimp

    cd computer-graphics/lib
    git clone https://github.com/assimp/assimp
    cd assimp
    cmake -G Ninja -DASSIMP_BUILD_TESTS=off -DASSIMP_INSTALL=off -S . -B build
    cd build
    ninja
  • stb-image

    github - stb

    cd computer-graphics/lib
    git clone https://github.com/nothings/stb.git

使用者介面(UI)

  • ImGui

    github - ImGui

    cd computer-graphics/lib
    git clone https://github.com/ocornut/imgui.git

編譯說明 (Build Instruction)

01_winBGIm_DVD (MinGW)

cd ./01_winBGIm_DVD
make

02_winBGIm_Snake (MinGW)

cd ./02_winBGIm_Snake
make

03_SFML_Snake (Visual Studio)

cd ./03_SFML_Snake
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
msbuild /p:Configuration=Release /p:Platform=x64
.\03_SFML_Snake\x64\Release\Snake_vs.exe

04_openGL_playground (MinGW)

本專案為學習現代 OpenGL 的基礎練習,主要參考以下教學清單進行實作:

教學來源:YouTube - OpenGL Course

cd ./04_openGL_playground
make

05_openGL_robot (Visual Studio)

cd computer-graphics

# 建立目標目錄
mkdir -p ./05_openGL_robot/RobotControlSystem/LIB

# 複製 stb_image
cp ./lib/stb/stb_image.h ./05_openGL_robot/RobotControlSystem/LIB/

# 複製 ImGui 核心檔案
cp ./lib/imgui/*.h ./05_openGL_robot/RobotControlSystem/LIB/
cp ./lib/imgui/*.cpp ./05_openGL_robot/RobotControlSystem/LIB/

# 複製 ImGui Backends (GLFW & OpenGL3)
cp ./lib/imgui/backends/imgui_impl_glfw.cpp ./05_openGL_robot/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_glfw.h ./05_openGL_robot/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_opengl3.cpp ./05_openGL_robot/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_opengl3.h ./05_openGL_robot/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_opengl3_loader.h ./05_openGL_robot/RobotControlSystem/LIB/

## 編譯專案
cd 05_openGL_robot
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
msbuild /p:Configuration=Release /p:Platform=x64
cp -r ./RobotControlSystem/Shader ./x64/Release
cp -r ./RobotControlSystem/model_Robot ./x64/Release
cd ./x64/Release
.\RobotControlSystem.exe

06_openGL_car (Visual Studio)

cd computer-graphics

# 建立目標目錄
mkdir -p ./06_openGL_car/RobotControlSystem/LIB

# 複製 stb_image
cp ./lib/stb/stb_image.h ./06_openGL_car/RobotControlSystem/LIB/

# 複製 ImGui 核心檔案
cp ./lib/imgui/*.h ./06_openGL_car/RobotControlSystem/LIB/
cp ./lib/imgui/*.cpp ./06_openGL_car/RobotControlSystem/LIB/

# 複製 ImGui Backends (GLFW & OpenGL3)
cp ./lib/imgui/backends/imgui_impl_glfw.cpp ./06_openGL_car/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_glfw.h ./06_openGL_car/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_opengl3.cpp ./06_openGL_car/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_opengl3.h ./06_openGL_car/RobotControlSystem/LIB/
cp ./lib/imgui/backends/imgui_impl_opengl3_loader.h ./06_openGL_car/RobotControlSystem/LIB/

## 編譯專案
cd 06_openGL_car
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
msbuild /p:Configuration=Release /p:Platform=x64
cp -r ./RobotControlSystem/Shader ./x64/Release
cp -r ./RobotControlSystem/model_Robot ./x64/Release
cd ./x64/Release
.\RobotControlSystem.exe

聲明 (Notice)

  • 模型版權05_openGL_robot/06_openGL_car 專案中所使用的 3D 模型檔案為外部資源,並非本人創作,故不包含在倉儲中。使用者需自行準備相容之模型檔案進行測試。

About

A collection of Computer Graphics projects ranging from 2D simulations & AI games to 3D OpenGL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages