rswinkle/PortableGL
FreeAn implementation of OpenGL 3.x-ish in clean C
FreeFree tier
About rswinkle/PortableGL
PortableGL is an implementation of OpenGL 3.x core (mostly) in clean C99, packaged as a single header library in the style of the stb libraries. It compiles as C++ and can be easily integrated into almost any codebase. Shaders are written as ordinary C/C++ functions rather than GLSL, and uniforms are passed via pointers to user-defined structs, simplifying the API. The library supports arbitrary 32- and 16-bit color buffer formats and can work with any system that accepts a framebuffer, including SDL2, X11, and Win32 backends. It includes a variety of demos and examples, such as a port of Michael Fogleman's Craft, making it suitable for learning, prototyping, and embedded 3D graphics.
Key Features
Single header library (stb-style) written in clean C99
Compiles cleanly as C++
Supports arbitrary 32- and 16-bit color buffer formats
Multiple backends: SDL2, X11, Win32
Shaders implemented as C/C++ functions (no GLSL parser needed)
Uniforms passed via pointer to user-defined structs
Portable across platforms with minimal dependencies
Includes demos, examples, and a port of Craft
Pros & Cons
Pros
- Extremely portable – works wherever C99 compiles
- Minimal dependencies – single header file
- Easy to integrate: no build system overhead
- No need for GLSL parsing or compilation
- Open source and free (MIT license)
- Multiple backend support (SDL2, X11, Win32)
Cons
- Only implements a subset of OpenGL 3.x core – not feature-complete
- Shaders must be written as C/C++ functions, not standard GLSL
- Software rendering only – performance limited compared to hardware
- Limited to 32- and 16-bit color buffers (no floating-point HDR framebuffers mentioned)
Best For
Learning OpenGL 3.x concepts in a pure software rendererPrototyping 3D graphics applications without GPU dependenciesEmbedding 3D rendering into cross-platform projectsEducational tool for graphics programming coursesCreative coding and shader art development
FAQ
How are shaders handled in PortableGL?
Shaders are written as ordinary C/C++ functions that conform to a specific prototype, avoiding the need for a GLSL parser or compiler. Uniforms are passed via a pointer to a user-defined struct.
What backends are available for PortableGL?
Almost all demos use SDL2, but the repository includes backends for X11 (xlib) and Win32. The library can theoretically work with any system that takes a 32- or 16-bit framebuffer.
Does PortableGL support all of OpenGL 3.x?
It implements OpenGL 3.x core mostly, but not fully. It focuses on portability, matching the API within reason, ease of use, and speed.