Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

OpenGL

> 编程语言
Open source

OpenGL 3 and 4 examples using GLSL

2.6K stars0 likes0 views
WebsiteGitHub

About

OpenGL 3 and 4 examples using GLSL

OpenGL

OpenGL 3 and OpenGL 4 with GLSL

Changelog

v3.2.1

Security and correctness fixes across all 52 examples:

  • Fixed Example36 SSBO allocation (std430 stride was 24 B instead of 32 B — 25 % undersized).
  • Added missing glMemoryBarrier calls in Examples 21, 30, 36, 45.
  • Fixed glUniform4fv/glUniform2fv count (vec4/vec2 elements, not floats) in Example15.
  • Moved 900 KB stack arrays to static storage in Examples 29, 37.
  • Fixed glDeleteRenderbuffers on texture names in Examples 12, 34.
  • Added NULL-source guards for glusFileLoadText in Examples 47, 51, 52.
  • Added missing glViewport in Example27 reshape().
  • Fixed resource leaks (programs, VAOs, VBOs, text files) in Examples 09, 12, 14, 22, 27, 31, 35, 36, 50.
  • Fixed fur VAO attribute locations in Example26.
  • Fixed glDrawBuffer(GL_COLOR_ATTACHMENT0) on default framebuffer in Examples 28, 31.
  • Fixed double angle advancement in Example19.
  • Fixed Gerstner wave steepness index in Example15.
  • Added FBO completeness checks in Examples 09, 33, 48, 49, 50.
  • Checked GLUS return values across all examples (316 call sites).
  • Replaced deprecated FetchContent_Populate in root CMakeLists.txt.
  • Requires GLUS v1.1.1.

v3.2.0

  • Migrated the glTF examples (48-52) onto the GLUS glTF 2.0 loader (glusGltfLoadScene / glusGltfGetCgltfData). GLUS now provides cgltf + stb_image and exposes GLUS_SHADER_DIR; the copied OpenGL/GLUS/ folder is gone.
  • Requires GLUS v1.1.0. GLUS is taken from the sibling local checkout ../GLUS when present, otherwise fetched from McNopper/GLUS.
  • Refreshed screenshots.

v3.1.1

  • Added Example52 – 3D Gaussian Splatting with view-direction SH rotation.
  • Example51: corrected spherical-harmonics handling for rotated splat nodes (Wigner-D bridged to the glTF/3DGS SH sign convention via the Condon-Shortley phase).
  • Both splatting examples: auto-rotation is off by default and toggles with Space.
  • Requires GLUS v1.0.1 (band-3 SH rotation fix).

License

The project is distributed under the MIT License — see LICENSE.

These examples are built on GLUS (MIT), which bundles glfw, glew, cgltf and stb — their notices live in the GLUS third-party file. The dependencies and bundled assets added by this repository — McNopper/EGL (MIT) and the Einstein / phoenix 3D models (CC-BY-4.0) — are documented in THIRD-PARTY.md; per-example attributions are noted in each example's section below.

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:

bash
cmake --version

Should show version 3.14 or higher.

Check if Git is installed:

bash
git --version

Building

Dependencies (GLUS, GLFW and GLEW) are automatically downloaded and built via CMake FetchContent. GLUS is taken from the sibling local checkout ../GLUS when present (multi-repo development layout), and otherwise fetched from its own repository at github.com/McNopper/GLUS. GLUS in turn provides cgltf and stb_image, and exposes its shader directory through the GLUS_SHADER_DIR compile definition.

Windows (Visual Studio):

bash
mkdir build && cd build
cmake ..
cmake --build .

Linux / macOS:

bash
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 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)
  • Example50 - Rec.2020 HDR via EGL (OpenGL 4.6)
  • Example51 - 3D Gaussian Splatting via KHR_gaussian_splatting (OpenGL 4.6)
  • Example52 - 3D Gaussian Splatting with view-direction SH rotation (OpenGL 4.6)

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)

Real-time global illumination using voxel cone tracing based on [C

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Cexamplesopengl

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言