Skip to content

Instantly share code, notes, and snippets.

@giraphics
Last active May 4, 2026 06:01
Show Gist options
  • Select an option

  • Save giraphics/9cf889f71cfc795a295966cf0cb0843d to your computer and use it in GitHub Desktop.

Select an option

Save giraphics/9cf889f71cfc795a295966cf0cb0843d to your computer and use it in GitHub Desktop.
OpenGL WSL Setup
# 🧩 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