Last active
May 4, 2026 06:01
-
-
Save giraphics/9cf889f71cfc795a295966cf0cb0843d to your computer and use it in GitHub Desktop.
OpenGL WSL Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # π§© WSL2 Build & Run Guide β OpenGL 4.5 (`tutorial-1`) | |
| ## π Context | |
| You have a C++ OpenGL 4.5 project originally built for Windows + Visual Studio. | |
| This guide shows how to build and run it inside **WSL2 (Ubuntu)** using CMake. | |
| --- | |
| ## β Prerequisites (Windows) | |
| * Windows 10 (19041+) or Windows 11 (recommended) | |
| * GPU with updated drivers: | |
| * NVIDIA (WSL2 driver β₯ 470.76) | |
| * AMD / Intel (latest WHQL) | |
| * ~2 GB free disk space | |
| --- | |
| ## π§ Step 1 β Install WSL2 | |
| ```powershell | |
| wsl --install | |
| # OR | |
| wsl --install -d Ubuntu-22.04 | |
| wsl --set-default-version 2 | |
| ``` | |
| Reboot β create Ubuntu username/password. | |
| Check: | |
| ```powershell | |
| wsl --list --verbose | |
| ``` | |
| --- | |
| ## π₯οΈ Step 2 β Verify GUI / OpenGL | |
| Inside Ubuntu: | |
| ```bash | |
| echo $DISPLAY | |
| ``` | |
| * Windows 11 β works out of the box (WSLg) | |
| * Windows 10 β install X server (VcXsrv/X410) | |
| --- | |
| ## π§ Step 3 β Install Dependencies | |
| ```bash | |
| sudo apt update && sudo apt upgrade -y | |
| sudo apt install -y \ | |
| build-essential cmake git ninja-build \ | |
| libx11-dev libxrandr-dev libxinerama-dev \ | |
| libxcursor-dev libxi-dev libxext-dev \ | |
| libgl1-mesa-dev libglu1-mesa-dev \ | |
| mesa-utils | |
| ``` | |
| Check OpenGL: | |
| ```bash | |
| glxinfo | grep "OpenGL version" | |
| ``` | |
| --- | |
| ## π Step 4 β Copy Project | |
| **Recommended:** | |
| ```bash | |
| cp -r /mnt/c/Users/parminder_local/Downloads/2026/tutorial-1 ~/tutorial-1 | |
| cd ~/tutorial-1 | |
| ``` | |
| --- | |
| ## π Step 5 β Init Submodules | |
| ```bash | |
| git submodule update --init --recursive | |
| ``` | |
| --- | |
| ## βοΈ Step 6 β Configure (CMake) | |
| ```bash | |
| mkdir build && cd build | |
| cmake .. \ | |
| -G "Unix Makefiles" \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DGLFW_BUILD_X11=ON \ | |
| -DGLFW_BUILD_WAYLAND=OFF | |
| ``` | |
| --- | |
| ## ποΈ Step 7 β Build | |
| ```bash | |
| make -j$(nproc) | |
| ``` | |
| Output: | |
| ``` | |
| build/projects/tutorial-1/tutorial-1 | |
| ``` | |
| --- | |
| ## βΆοΈ Step 8 β Run | |
| ```bash | |
| cd ~/tutorial-1/build/projects/tutorial-1 | |
| ./tutorial-1 | |
| ``` | |
| Expected: | |
| * 800Γ600 window | |
| * Colored quad rendered | |
| * **U** β toggle animation | |
| * **ESC** β exit | |
| --- | |
| ## π οΈ Troubleshooting | |
| | Issue | Fix | | |
| | ----------------- | ------------------------------ | | |
| | `DISPLAY not set` | Use WSLg or install X server | | |
| | OpenGL < 4.5 | Install GPU driver or use Mesa | | |
| | Missing glfw | Run submodule update | | |
| | `GL/glew.h` error | Install `libgl1-mesa-dev` | | |
| | `-lX11` error | Install `libx11-dev` | | |
| | Slow FPS | GPU not used (llvmpipe) | | |
| --- | |
| ## π Key Files | |
| * `CMakeLists.txt` β build config | |
| * `glhelper.cpp` β OpenGL 4.5 check | |
| * `lib/glfw/` β window/input | |
| * `lib/glew/` β extension loader | |
| --- | |
| ## β Verification Checklist | |
| * `glxinfo` shows OpenGL 4.5+ | |
| * CMake runs successfully | |
| * Build completes without errors | |
| * App launches and renders | |
| * Input keys work (U / ESC) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment