This repository contains a collection of examples for the PyNGL library and used in teaching across a number of NCCA courses.
It is expected you will use uv to run all the python applications. The RunDemos.py will launch all the demos in the repository.
There are two main types of demos in this repository:
OpenGL Demos : These are demos that use Modern core profile OpenGL for rendering.
WebGPU Demos : These are demos that use WebGPU for rendering and in a number of cases are also available as OpenGL demos.
You can see the Source for the PyNGL on GitHub and it can be installed via PyPi Full details of PyNGL and how to use it can be found at https://ncca.github.io/PyNGL/
Each demo lives in its own folder with a README.md explaining it. Click a preview or demo name below to open that folder.
To quickly run all the demos use the smoketest_all.py script which will launch all the demos for a few seconds and then exit, useful for quickly verifying that all demos are working.
Getting Started / Templates
Preview
Demo
Description
2DDrawingOpenGL
2D drawing with OpenGL
Camera
Camera / view and projection setup
Lights
Basic lighting
ShadingModels
Comparison of shading models
ScreenTri
Full-screen triangle technique
OpenGLPrimRestart
Primitive restart index
ResetLine
Animated line field using primitive restart in OpenGL and line-list expansion in WebGPU
FrustumCull
View frustum culling
FontRendering
Text / font rendering
TexelFetch
Texture Buffer Object + texelFetch: animated height grid (OpenGL + WebGPU)
LoadShaderFromJSon
JSON-driven shader assembly: noise-shaded teapot (OpenGL + WebGPU)
TextureCompressor
DXT1/S3TC compressed-texture viewer + a from-scratch Python encoder
GameKeyControl
Bitmask-indexed motion table for held multi-key combos, with record/playback (OpenGL + WebGPU)
ImageMaze
Image pixels turned into a coloured cube maze with collision-aware actor controls (OpenGL + WebGPU)
Preview
Demo
Description
Instancing
GPU instancing vs a Python draw-call loop, with an on-screen frame-time HUD (OpenGL + WebGPU)
Preview
Demo
Description
ObjViewer
Load and view Obj meshes
ColourObj
Obj mesh with per-vertex colour
Obj2Numpy
Convert Obj data to NumPy arrays
KleinBottle
Procedural Klein bottle
MarchingCubes
Metaballs polygonised into a mesh every frame with vectorised Marching Cubes
Preview
Demo
Description
SceneGraph
A robot arm built from a minimal, unit-tested transform-hierarchy Node class
MatrixStack
Hand-rolled push/pop matrix stack driving a hierarchy of trolls and an orbiting sphere ring (OpenGL + WebGPU)
LookAtDemos
Interactive perspective camera against a 2x2 orthographic multi-view comparison of the same scene (OpenGL + WebGPU)
ViewToWorldTransform
Shift-click to unproject a screen position into a world-space point (OpenGL + WebGPU)
AffineTransforms
Translate/rotate/scale composition order (RTS vs TRS vs axis-angle) shown live against a Mat4 readout (OpenGL + WebGPU)
Preview
Demo
Description
SkeletalAnimation
Linear blend skinning vs dual-quaternion skinning, and the "candy wrapper" artefact that tells them apart (OpenGL)
MassSpring
Damped mass spring chain with RK4 integration, from a single spring up to a rope
SkinnedMeshImport
Importing a rigged mesh with impasse (Python assimp) and skinning it on the GPU (OpenGL and WebGPU)
MorphObj
Vertex-shader blending between three OBJ poses (OpenGL + WebGPU)
BVHViewer
BVH motion-capture player with a scrubbable timeline, playback range and Four Views layout (OpenGL + WebGPU)
Preview
Demo
Description
SimpleTexture
Basic texture mapping
AnimatedTextures
Animated / scrolling textures
ShowMipmap
Visualising mipmap levels
ImageHeightMap
Displacement from a height map image
NormalMapping
Tangent-space normal mapping
PBR/SimplePBR
Simple physically based rendering
PBR/PBRTexture
Textured physically based rendering (OpenGL and WebGPU versions)
PBR/IBL
Image-based ambient lighting for PBR: numpy-precomputed irradiance map + BRDF split-sum LUT (OpenGL)
PBR/HDRI
Full HDRI image-based lighting: GPU-baked irradiance, prefiltered specular chain and BRDF LUT from a real HDR panorama (OpenGL and WebGPU)
PBR/HDRIBaker
Bakes the split-sum IBL maps from an HDRI to a .npz once, offline; a separate WebGPU demo loads them with no runtime bake
Billboards
Camera-facing quads: fixed / cylindrical / spherical billboarding modes (OpenGL)
Preview
Demo
Description
Blending
Alpha blending, depth write and sorting toggles (OpenGL + WebGPU)
OITransparency
Weighted blended order-independent transparency (OpenGL + WebGPU)
Preview
Demo
Description
SkyBoxEnvMap
Procedural cubemap skybox with reflect/refract/Fresnel teapot (OpenGL + WebGPU)
Preview
Demo
Description
CurveDemos
Curve types and evaluation
EasingFunctions
Full Penner easing set with combo box selection and live matplotlib graph
Interpolation
Interpolation techniques
QuatSlerp
Quaternion spherical interpolation
GimbalLock
Euler vs quaternion orientation, side by side, with a scripted gimbal-lock demonstration
Preview
Demo
Description
Collisions/SphereSphere
Two moving spheres bounce off two static ones (analytic sphere/sphere test) (OpenGL + WebGPU)
Collisions/RaySphere
N spheres tested each tick against 2 animated sweeping rays (OpenGL + WebGPU)
Collisions/RayTriangle
N triangles tested every frame against a keyboard-moved ray (Moller-Trumbore) (OpenGL + WebGPU)
Collisions/SpherePlane
N falling spheres collide with a tiltable plane (OpenGL + WebGPU)
Collisions/BoundingBox
N spheres bounce inside a cubic bounding box, optional sphere/sphere checking (OpenGL + WebGPU)
OctreeAbstract
Perfect octree broad phase with instanced particle rendering (OpenGL + WebGPU)
MuJoCoNGL
Rigid body physics with MuJoCo, spawning bodies into a model that cannot be added to (OpenGL)
Framebuffers & Post Processing
Preview
Demo
Description
DefferedLighting
Deferred lighting (WebGPU)
WebGPUShadows
PCF shadow mapping (WebGPU)
ShadowMapping
Two-pass depth-map shadows with PCF, bias and culling toggles (OpenGL)
Spotlight
Four animated cone-attenuation spotlights sweeping a grid of teapots (OpenGL + WebGPU)
Preview
Demo
Description
RayMarchingSDF
Sphere-traced signed distance fields, smooth-blended primitives, soft shadows + AO (OpenGL & WebGPU)
Geometry & Tessellation Shaders
Preview
Demo
Description
GeometryTessellation
Geometry-shader normal visualiser + distance-LOD tessellated noise plane (OpenGL)
ShadedGrid
Animated Phong-shaded wave grid with geometry-shader face/vertex normal visualisation (OpenGL)
Preview
Demo
Description
UBOStorageBuffers
UBO shared across two shader programs + std140 padding trap (OpenGL); runtime-sized storage-buffer point lights (WebGPU)
Preview
Demo
Description
WebGPUMultiGeo
Multiple geometry in one WebGPU scene
Preview
Demo
Description
GUIDemos/PySideGUIOpenGL
PySide GUI driving an OpenGL widget
GUIDemos/NGLWidgetsOpenGL
NGL widgets with OpenGL
GUIDemos/WebGPUGUI
GUI driving a WebGPU widget
GUIDemos/QMLOverlayApp
QWidget OpenGL viewport with a transparent QQuickWidget overlay of floating ncca.ngl.qml panels
GUIDemos/QMLWebGPUOverlay
WebGPU (offscreen) viewport with a transparent QQuickWidget overlay of floating ncca.ngl.qml panels
MathNodeEditor
PySide node editor for wiring PyNGL vector, matrix, camera, quaternion and Obj mesh operations, with a live 3D mesh viewer node
SciFiUI
Retro sci-fi CRT terminal: Unknown Pleasures style wireframe terrain fly-over, clickable buttons, scrolling log and a two-pass CRT post process
This project has use various AI tools (Claude and Codex and OpenCode ) to assist with development.
The initial phases were for the full port of NGL9Demos to PyNGL (C++ to Python conversion) and additional testing. Most of the work is shown in the docs section of the repository, and I have also written about various things on my blog here .
There will be a full write-up of my setup and usage of AI on the Blog soon.
See LICENSE.txt or just use the Beerware License