close
Skip to content

McNopper/OpenGL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

307 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenGL

OpenGL 3 and OpenGL 4 with GLSL

Build Instructions

Prerequisites

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

Verify Installation

Check if CMake is installed:

cmake --version

Should show version 3.14 or higher.

Check if Git is installed:

git --version

Building

Dependencies (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 ..
make

Executables will be in the Binaries/ directory.

Dependencies

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

Examples

All 47 examples demonstrate various OpenGL 3.x and 4.x features with GLSL shaders.

Example01 - Basic window and OpenGL 3 initialization

Example01

Example02 - Rendering of a triangle

Example02

Example03 - Grey filter

Example03

Example04 - Perspective rendering of a cube

Example04

Example05 - Phong rendering of a sphere

Example05

Example06 - Texturing of a cube

Example06

Example07 - Normal mapping

Example07

Example08 - Environment/cube mapping

Example08

Example09 - GPU Particles

Example09

Example10 - Geometry shader

Example10

Example11 - Reflection and refraction

Example11

Example12 - Shadow mapping

Example12

Example13 - Simple tessellation (OpenGL 4.1)

Example13

Example14 - Terrain rendering (OpenGL 4.1)

Example14

Example15 - Water rendering

Example15

Example16 - Model loading and rendering

Example16

Example17 - Clipping planes and two sided rendering

Example17

Example18 - Using stencil buffer and clipping planes

Example18

Example19 - Render to texture and planar reflection

Example19

Example20 - Texture matrix, alpha blending and discarding

Example20

Example21 - Compute shader (OpenGL 4.3)

Example21

Example22 - Shadow volumes

Example22

Example23 - Displacement mapping (OpenGL 4.1)

Example23

Example24 - Erode effect using perlin noise

Example24

Example25 - Model with groups and materials

Example25

Example26 - Fur rendering

Example26

Example27 - Projection shadow for directional light

Example27

Example28 - Screen space ambient occlusion (SSAO) (OpenGL 4.1)

Example28

Example29 - CPU ray tracing

Example29

Example30 - GPU ray tracing using compute shader (OpenGL 4.3)

Example30

Example31 - Many lights using deferred shading (OpenGL 4.1)

Example31

Example32 - BRDF and IBL rendering (OpenGL 4.1)

Example32

Example33 - Real-Time BRDF and IBL rendering (OpenGL 4.1)

Example33

Example34 - Subsurface scattering

Example34

Example35 - Order independent transparency using depth peeling

Example35

Example36 - Order independent transparency using linked list (OpenGL 4.4)

Example36

Example37 - CPU ray marching

Example37

Example38 - Basic usage of program pipeline and separable programs (OpenGL 4.1)

Example38

Example39 - Basic usage of program pipeline, separable programs and shader subroutines (OpenGL 4.1)

Example39

Example40 - Cloth simulation using compute shader (OpenGL 4.3)

Example40

Example41 - Ocean wave height/normal map calculation with FFT using compute shader (OpenGL 4.3)

Example41

Example42 - Fast Approximate Anti Aliasing - FXAA (OpenGL 4.3)

Example42

Example43 - Scene with several models having groups and materials

Example43

Example44 - Conservative rasterization

Example44

Example45 - GPU voxelization (OpenGL 4.4)

Example45

Example46 - Voxel cone tracing - Global illumination (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)

Example46

Example47 - 3D spatial colour sort — RGB cube (OpenGL 4.6)

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.

Example47

Example48 - glTF 2.0 PBR renderer with Image-Based Lighting (OpenGL 4.6)

Example48

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:

  • cgltf by Johannes Kuhlmann — MIT License
  • stb_image by Sean Barrett — MIT License / Public Domain

Model: This work is based on "Albert Einstein" by pattarrian licensed under CC-BY-4.0

Example49 - glTF 2.0 PBR + IBL + Skeletal Animation (OpenGL 4.6)

Example49

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:

  • cgltf by Johannes Kuhlmann — MIT License
  • stb_image by Sean Barrett — MIT License / Public Domain

Model: This work is based on "phoenix bird" by NORBERTO-3D licensed under CC-BY-4.0

About

OpenGL 3 and 4 examples using GLSL

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors