OpenGL 3 and OpenGL 4 with GLSL
Required:
- CMake 3.14 or higher - Download
- C/C++ Compiler:
- Windows: Visual Studio 2013+ (MSVC)
- Linux: GCC or Clang
- macOS: Xcode Command Line Tools
- Git - For fetching dependencies
- OpenGL 3.2+ compatible graphics driver
Check if CMake is installed:
cmake --versionShould show version 3.14 or higher.
Check if Git is installed:
git --versionDependencies (GLFW and GLEW) are automatically downloaded and built via CMake FetchContent.
Windows (Visual Studio):
mkdir build && cd build
cmake ..
cmake --build .Linux / macOS:
mkdir build && cd build
cmake ..
makeExecutables will be in the Binaries/ directory.
All dependencies are automatically fetched and built:
- GLFW 3.4 - Windowing and input
- GLEW 2.2.0 - OpenGL Extension Wrangler
- OpenGL 3.2+ - System graphics library
All 47 examples demonstrate various OpenGL 3.x and 4.x features with GLSL shaders.
- Example01 - Basic window and OpenGL 3 initialization
- Example02 - Rendering of a triangle
- Example03 - Grey filter
- Example04 - Perspective rendering of a cube
- Example05 - Phong rendering of a sphere
- Example06 - Texturing of a cube
- Example07 - Normal mapping
- Example08 - Environment/cube mapping
- Example09 - GPU Particles
- Example10 - Geometry shader
- Example11 - Reflection and refraction
- Example12 - Shadow mapping
- Example13 - Simple tessellation (OpenGL 4.1)
- Example14 - Terrain rendering (OpenGL 4.1)
- Example15 - Water rendering
- Example16 - Model loading and rendering
- Example17 - Clipping planes and two sided rendering
- Example18 - Using stencil buffer and clipping planes
- Example19 - Render to texture and planar reflection
- Example20 - Texture matrix, alpha blending and discarding
- Example21 - Compute shader (OpenGL 4.3)
- Example22 - Shadow volumes
- Example23 - Displacement mapping (OpenGL 4.1)
- Example24 - Erode effect using perlin noise
- Example25 - Model with groups and materials
- Example26 - Fur rendering
- Example27 - Projection shadow for directional light
- Example28 - Screen space ambient occlusion (SSAO) (OpenGL 4.1)
- Example29 - CPU ray tracing
- Example30 - GPU ray tracing using compute shader (OpenGL 4.3)
- Example31 - Many lights using deferred shading (OpenGL 4.1)
- Example32 - BRDF and IBL rendering (OpenGL 4.1)
- Example33 - Real-Time BRDF and IBL rendering (OpenGL 4.1)
- Example34 - Subsurface scattering
- Example35 - Order independent transparency using depth peeling
- Example36 - Order independent transparency using linked list (OpenGL 4.4)
- Example37 - CPU ray marching
- Example38 - Basic usage of program pipeline and separable programs (OpenGL 4.1)
- Example39 - Basic usage of program pipeline, separable programs and shader subroutines (OpenGL 4.1)
- Example40 - Cloth simulation using compute shader (OpenGL 4.3)
- Example41 - Ocean wave height/normal map calculation with FFT using compute shader (OpenGL 4.3)
- Example42 - Fast Approximate Anti Aliasing - FXAA (OpenGL 4.3)
- Example43 - Scene with several models having groups and materials
- Example44 - Conservative rasterization
- Example45 - GPU voxelization (OpenGL 4.4)
- Example46 - Voxel cone tracing - Global illumination (OpenGL 4.6)
- Example47 - 3D spatial colour sort — RGB cube (OpenGL 4.6)
- Example48 - glTF 2.0 PBR renderer with Image-Based Lighting (OpenGL 4.6)
- Example49 - glTF 2.0 PBR + IBL + Skeletal Animation (OpenGL 4.6)
Real-time global illumination using voxel cone tracing based on Crassin et al. 2011. The Sponza scene is first voxelized into a 256³ RGBA16F 3D texture with a dominant-axis geometry shader. Mipmaps are generated for the voxel grid, then the final pass traces six diffuse cones plus a specular cone per fragment to compute indirect illumination, ambient occlusion, and specular reflections. A small emissive sphere orbits the scene as the sole indirect light source (Space to pause/resume).
Simplifications vs. the original paper:
| Aspect | Paper | This implementation |
|---|---|---|
| Scene representation | Sparse Voxel Octree (SVO) — adaptive, high-resolution | Flat 256³ RGBA16F 3D texture — simpler, lower resolution |
| Voxel filtering | Anisotropic pre-filtering: per-face directional radiance propagated up the octree | Isotropic glGenerateMipmap box filter |
| Radiance storage | Per-face (6 directions) for directional shadowing | Single isotropic value per voxel |
| Voxel write | Atomic accumulation when multiple triangles cover the same voxel | Plain imageStore (last-write-wins) |
What already exists. Odd-even transposition sort was described by Knuth (1973) and maps directly to parallel hardware. Shearsort — sorting a 2D grid by alternating row and column passes — was introduced by Scherson & Sen (1986). Extending it to a 3D grid by cycling through three axis passes is a straightforward generalisation studied in the parallel computing literature. GPU sort implementations (bitonic, radix, odd-even) have existed since the mid-2000s.
What is the application insight. Using a 3D RGBA8 texture directly as the sort array, where the sort key of each element is its own colour — Red sorted along X, Green along Y, Blue along Z — with no index remapping. The data set is the complete RGB8 lattice: all N³ distinct colours, one per voxel, so every axis sort has a unique total order.
| Dispatch | Sort key | Converges to |
|---|---|---|
| X-axis lines | Red (R) | R increases with x |
| Y-axis lines | Green (G) | G increases with y |
| Z-axis lines | Blue (B) | B increases with z |
What makes it elegant. The choice of data produces a unique fixed-point property: the only configuration that simultaneously satisfies all three axis sorts is the perfect RGB cube,
texel(x, y, z).rgb = (x, y, z) × 255 / (N − 1)
This means correctness is self-evident — if the rendered cube shows a smooth
RGB gradient the sort has converged correctly, with no checksum or external
oracle needed. Starting from random colour noise the cube crystallises step by
step, making convergence visually striking. Corners map to pure colours:
(0,0,0)→black, (1,0,0)→red, (0,1,0)→green, (0,0,1)→blue,
(1,1,1)→white; the main diagonal becomes the greyscale ramp.
GL 4.6 highlight. The sort runs in a compute shader using shared memory
and two barrier() calls per pass (one after the read phase, one after the
write phase). At startup GL_MAX_COMPUTE_WORK_GROUP_SIZE and
GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS are queried and GRID_N is capped at 32
(32³ = 32 768 points, fits in shared memory on all hardware). Controls: Space
to start, +/- to adjust step delay, R to reshuffle.
Loads a glTF 2.0 scene and renders it with physically-based metallic-roughness shading and Image-Based Lighting (IBL). The IBL precomputation pipeline is provided by the GLUS library (glusIblBuild*).
Usage:
Example48 [model.gltf] [panorama.hdr]
Defaults to einstein/scene.gltf and sunny_rose_garden_4k.hdr in the working directory.
Controls: ↑/↓ camera height · ←/→ orbit speed · +/− zoom
Third-party licenses:
Model: This work is based on "Albert Einstein" by pattarrian licensed under CC-BY-4.0
Extends Example48 with TRS node animation and skeletal skinning. Animation interpolation (STEP, LINEAR, CUBICSPLINE) for vec3 and quaternion tracks is provided by the GLUS library (glusAnimationSample*).
Usage:
Example49 [model.gltf] [panorama.hdr]
Defaults to phoenix/scene.gltf and sunny_rose_garden_4k.hdr in the working directory.
Controls: ↑/↓ camera height · ←/→ orbit speed · +/− zoom
Third-party licenses:
Model: This work is based on "phoenix bird" by NORBERTO-3D licensed under CC-BY-4.0
















































