r/cpp • u/hendrixstring • Jun 03 '26
I spent 6 months building a zero-std, header-only graphics ecosystem from scratch—including my own container library
Hi everyone,
I wanted to share a massive passion project I've been refining: micro-gl (and its sister libraries). I needed a lightweight vector graphics engine for constrained environments, but I wanted absolute control over memory and types. I ended up falling down a 6-month rabbit hole.
The Core Architecture:
- Zero Standard Library (
std::): No hidden allocations. To support this, I spent an intense 3 weeks writing my own standalone container library (micro-containers) featuring AVL trees, an array-backed LRU pool, and a linear-probing hash map sized entirely at compile time via templates. - Type-Agnostic Math: The entire rasterizer is templated. It can run on raw
float,double, or custom fixed-point integer types (likeQformats) for microcontrollers without an FPU. The Engine Stack:
micro-gl: CPU-bound rasterizer handling textures, gradients, and Porter-Duff blending.micro-tess: A precision-agnostic polygon tessellator.nitro-gl: An OpenGL implementation that compiles C++ shader object hierarchies into monolithic GLSL strings at runtime, cached via MurmurHash.
Everything is purely header-only, allocator-aware, and optimized for extreme cache locality.
Repositories are open-source here:
- Graphics Engine (CPU): https://github.com/micro-gl/micro-gl
- Graphics Engine (GPU): https://github.com/micro-gl/nitro-gl
- Custom Containers: https://github.com/micro-gl/micro-containers
I would love to hear your thoughts on the template design and compile-time sizing strategies!
99
u/germandiago Jun 03 '26
Not sure why you would rule out containers out of the box. Looks to me like NIH syndrome a bit.
You can still, with containers, customize allocators and have lots of specialized containers in EASTL, Abseil and Boost.
28
u/arthurno1 Jun 03 '26
I can definitely understand the dedication, but if it isn't for learning purpose or a hobby, I have hard time to justify custom std library instead of using std library. You are asking for a C++11 compiler as a pre-requisita, it means you also have the std library.
Also, there are several 2d libraries available, Skia being one of them, documented, developed actively, used by an OS and lots of applications, easy to build and use, so I am kind of question why would you build your own if it isn't just for learning purpose or pure hobby, to be honest.
5
u/Tringi github.com/tringi Jun 03 '26
Why is every commit 5 years old?
9
u/sweetno Jun 03 '26
Why do people pray on header-only libraries? Or putting this stuff in PCH is the future?
14
u/Mediocre-Barber-8431 Jun 03 '26
insane dedication
2
u/cmblasko Jun 03 '26
This is really cool, really impressive dedication! Having total control over your code base is a lot of work but really empowering for personal projects, and you learn so much going the DIY route.
2
u/grandinj Jun 03 '26
I am sure you had fun, which I suppose was the point, but these days, the number of places where that kind of dedication to performance is necessary is pretty small. But maybe you can take your experience and help make one of the other C++ GUI better (like ImGui or wxWidgets or whatever) ? But you do you.
1
u/guybrush-77 Jun 03 '26
Looks very cool! I'm looking forward to trying it out.
Why not pick a standard licenses? The current one seems quite vague.
1
u/SUPERPOOP57 Jun 07 '26
C++ sub when someone makes something:
-8
u/Nuxij Jun 03 '26
I thought templates and stuff don't work in embedded platforms?