OpenGL in PyNGL
The ncca.ngl.opengl package is PyNGL's OpenGL rendering stack — the
Python equivalent of the C++ NGL library used in NCCA teaching. It targets
OpenGL 4.1 core profile (the maximum available on macOS) through
PyOpenGL, and is windowing-toolkit agnostic: the examples here use PySide6
(QOpenGLWindow), but glfw and SDL3 work the same way once a context
exists.
Unlike the maths classes, the OpenGL modules are not re-exported from
ncca.ngl — import them from the sub-package:
from ncca.ngl.opengl import ShaderLib, Primitives, VAOFactory
What the package gives you:
ShaderLib— a singleton registry of named shader programs, with four ready-made shaders (DefaultShader.COLOUR,DIFFUSE,CHECKER,TEXT), GLSL loading/compiling/linking, andset_uniform/set_uniform_bufferfor typed uniform upload. This is the conventional entry point — application code rarely touchesShaderorShaderProgramdirectly.Primitives— stock meshes (teapot, bunny, dragon, cube, …) and parametric shapes (sphere, torus, cone, …) as one-line drawables.- VAO abstraction —
VAOFactorycreatesSimpleVAO,SimpleIndexVAO, orMultiBufferVAOwrappers around vertex array objects, so custom geometry needs no rawglGenVertexArrayscode. Obj/BaseMesh— Wavefront OBJ loading straight to a drawable VAO (Objitself lives inncca.nglbut builds on this package).TextureandText— image textures (Pillow-backed) and font rendering (freetype glyph atlas + geometry-shader quads).PySideEventHandlingMixin— drop-in mouse rotate/pan/zoom camera controls for PySide6 windows.
The pages in this section
- Getting Started with OpenGL — the
QOpenGLWindowlifecycle, the surface-format setup you must not skip, and a complete spinning-teapot application. - Shaders and ShaderLib — using the built-in shaders (and their required uniforms), loading your own GLSL, and uniform buffer objects.
- Geometry: Primitives, Meshes, and VAOs — stock and parametric primitives, OBJ files, textures, and building custom geometry with the VAO factory.
- API Reference — VAO, Shaders, Geometry, Image and Texture, and Text.
Complete examples
The PyNGLDemos repository has a
runnable demo per topic: BlankPySide6NGL (the starting template, with
and without the event mixin), SimplePyNGL (full manual event handling,
PBR, UBOs), VAOPrimitives, VertexArrayObject (custom VAOs),
ObjViewer, SimpleTexture, ShadingModels, Lights, FBODemos, and
FontRendering.