Top Related Projects
A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
OpenGL Mathematics (GLM)
stb single-file public domain libraries for C/C++
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
Quick Overview
McNopper/OpenGL is a comprehensive GitHub repository containing OpenGL examples and tutorials. It covers a wide range of OpenGL topics, from basic rendering to advanced techniques, and includes implementations in various programming languages such as C, C++, and Java.
Pros
- Extensive collection of OpenGL examples covering many aspects of 3D graphics programming
- Implementations in multiple programming languages, making it accessible to a broader audience
- Well-organized structure with separate folders for different topics and languages
- Includes both basic and advanced OpenGL techniques, suitable for beginners and experienced developers
Cons
- Some examples may be outdated or use deprecated OpenGL features
- Limited documentation for some of the more complex examples
- Not actively maintained, with the last update being several years ago
- May require additional setup or dependencies for certain examples
Code Examples
Here are a few short code examples from the repository:
- Basic OpenGL window setup (C++):
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL Window", NULL, NULL);
glfwMakeContextCurrent(window);
glewInit();
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
- Loading a shader (C++):
GLuint loadShader(GLenum shaderType, const char* shaderSource)
{
GLuint shader = glCreateShader(shaderType);
glShaderSource(shader, 1, &shaderSource, NULL);
glCompileShader(shader);
return shader;
}
- Drawing a simple triangle (C++):
GLfloat vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
GLuint VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)0);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
Getting Started
To get started with the McNopper/OpenGL repository:
- Clone the repository:
git clone https://github.com/McNopper/OpenGL.git - Navigate to the desired example folder (e.g.,
cd OpenGL/Example01) - Follow the specific build instructions in the README file for the chosen example
- Compile and run the example using the provided build system (usually CMake)
Note that you may need to install additional dependencies such as GLEW, GLFW, or other libraries depending on the specific example you're working with.
Competitor Comparisons
A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
Pros of GLFW
- More widely used and actively maintained
- Cross-platform support for Windows, macOS, and Linux
- Extensive documentation and community support
Cons of GLFW
- Focused solely on window creation and input handling
- Requires additional libraries for advanced graphics functionality
Code Comparison
OpenGL:
#include "GL/glus.h"
GLUSboolean init(GLUSvoid)
{
// OpenGL initialization code
}
GLFW:
#include <GLFW/glfw3.h>
int main(void)
{
if (!glfwInit())
return -1;
// GLFW initialization code
}
Summary
GLFW is a lightweight, cross-platform library for creating windows with OpenGL contexts and handling input and events. It's widely used and well-maintained, making it a popular choice for OpenGL development.
OpenGL, on the other hand, is a more comprehensive graphics library that includes additional utilities and examples. It may be better suited for those looking for a more complete graphics solution out of the box.
While GLFW excels in its focused approach and cross-platform support, OpenGL offers a broader range of graphics-related functionality. The choice between the two depends on the specific needs of your project and your familiarity with OpenGL development.
OpenGL Mathematics (GLM)
Pros of GLM
- Specialized mathematics library for graphics programming
- Header-only, making it easy to integrate into projects
- Extensive documentation and community support
Cons of GLM
- Focused solely on mathematics, lacking broader OpenGL functionality
- May require additional libraries for complete graphics programming
Code Comparison
GLM:
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
glm::mat4 model = glm::rotate(glm::mat4(1.0f), glm::radians(45.0f), glm::vec3(0.0f, 1.0f, 0.0f));
OpenGL:
#include "GL/glus.h"
GLUSfloat matrix[16];
glusMatrix4x4Identityf(matrix);
glusMatrix4x4Rotatef(matrix, 45.0f, 0.0f, 1.0f, 0.0f);
Summary
GLM is a specialized mathematics library for graphics programming, offering easy integration and extensive documentation. However, it focuses solely on mathematics and may require additional libraries for complete graphics programming. OpenGL provides a broader range of functionality but may be less specialized in mathematics operations. The code comparison demonstrates the difference in syntax and approach between the two libraries for matrix operations.
stb single-file public domain libraries for C/C++
Pros of stb
- Single-file header libraries, making integration extremely simple
- Wide range of functionality (image loading, audio, fonts, etc.) in a lightweight package
- No external dependencies, enhancing portability
Cons of stb
- Less comprehensive OpenGL coverage compared to OpenGL
- May require more manual setup for complex rendering tasks
- Limited to C, while OpenGL supports C++
Code Comparison
OpenGL (setting up a window):
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main() {
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", NULL, NULL);
glfwMakeContextCurrent(window);
}
stb (loading an image):
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main() {
int width, height, channels;
unsigned char *image = stbi_load("image.png", &width, &height, &channels, 0);
}
Both repositories serve different purposes. OpenGL focuses on providing comprehensive OpenGL examples and utilities, while stb offers a collection of single-file libraries for various tasks, including some graphics-related functionalities. The choice between them depends on the specific needs of your project and your preferred development approach.
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
Pros of imgui
- Lightweight and easy to integrate into existing projects
- Extensive documentation and examples
- Active community and frequent updates
Cons of imgui
- Limited to immediate mode GUI, less suitable for complex layouts
- Requires more manual management of UI state
Code Comparison
imgui:
ImGui::Begin("My Window");
if (ImGui::Button("Click me!"))
doSomething();
ImGui::End();
OpenGL:
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glEnd();
Key Differences
- imgui focuses on GUI creation, while OpenGL is a graphics API
- OpenGL provides low-level graphics rendering capabilities
- imgui is built on top of graphics APIs like OpenGL
Use Cases
- imgui: Rapid prototyping, debug interfaces, tools
- OpenGL: 3D graphics, game development, scientific visualization
Learning Curve
- imgui: Relatively easy to learn and use quickly
- OpenGL: Steeper learning curve, requires understanding of graphics concepts
Performance
- imgui: Efficient for GUI rendering, but may impact overall performance
- OpenGL: High performance for graphics rendering when used correctly
Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
Pros of glad
- Easier to integrate into existing projects
- More flexible and customizable OpenGL loader generation
- Actively maintained with regular updates
Cons of glad
- Requires additional setup and configuration
- May have a steeper learning curve for beginners
- Limited documentation compared to OpenGL
Code Comparison
glad:
#include <glad/glad.h>
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
// Handle initialization error
}
OpenGL:
#include <GL/glew.h>
GLenum err = glewInit();
if (GLEW_OK != err) {
// Handle initialization error
}
Both repositories provide OpenGL loading functionality, but glad offers more flexibility in terms of API selection and extension loading. OpenGL, on the other hand, provides a more straightforward setup process and extensive documentation, making it potentially easier for beginners to get started.
glad is generally considered more modern and actively maintained, while OpenGL offers a more traditional approach to OpenGL loading. The choice between the two depends on project requirements, developer experience, and desired level of customization.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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
- 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)
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 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) |

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.

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

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)

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
Example50 - Rec.2020 HDR via EGL (OpenGL 4.6)

Extends Example49. New in this example:
- Rec.2020 (BT.2020) scene-referred working space instead of sRGB/Rec.709.
- HDR display output via McNopper/EGL. The renderer prefers
EGL_GL_COLORSPACE_BT2020_PQ_EXT(HDR10) and falls back through scRGB linear / BT.2020 linear / Display-P3 / sRGB depending on what the driver and surface advertise. - SMPTE 2086 / CTA-861.3 mastering metadata attached to the surface when an HDR colorspace is chosen.
- Reversed camera orbit direction.
- Diagnostic log
Example50.logwritten next to the executable, listing EGL vendor / version, all advertised colorspace extensions, and which candidate was used to create the surface.
Usage:
Example50 [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
Requires: an HDR-capable display with HDR enabled in Windows. On systems without HDR the app transparently falls back to sRGB output.
Additional third-party license:
- McNopper/EGL by Norbert Nopper â MIT License
Inherited third-party licenses (from Example49):
- 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
Example51 - 3D Gaussian Splatting via KHR_gaussian_splatting (OpenGL 4.6)

Implements the KHR_gaussian_splatting glTF 2.0 extension. Loads a .gltf file containing 3D Gaussian splats and renders them in real time using OpenGL 4.6 compute shaders and instanced rendering.
- GPU bitonic sort (adapted from Example 47) orders splats back-to-front by view-space depth each frame.
- Spherical harmonics evaluated up to band 3 (degree 3). Wigner-D rotation matrices (bands 1â3) rotate SH coefficients for nodes with a non-identity transform; helpers live in GLUS (
glusSHBuildRotation1f/2f/3f). - EWA covariance projection from the 3D Gaussian paper maps each splat to a screen-space ellipse quad.
- Premultiplied alpha compositing with large-splat culling to avoid degenerate full-screen artefacts.
- Dynamic configuration: SH degree and per-splat stride are detected automatically from the glTF primitive attributes.
Usage:
Example51 [path/to/model.gltf]
Defaults to ../Binaries/lego.gltf.
Controls: â/â orbit · â/â elevation · Page Up/Down zoom · auto-orbits at 0.5 rad/s
References:
- 3D Gaussian Splatting for Real-Time Radiance Field Rendering (Kerbl et al., SIGGRAPH 2023)
- KHR_gaussian_splatting extension specification
Top Related Projects
A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
OpenGL Mathematics (GLM)
stb single-file public domain libraries for C/C++
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot