Ask HN: Need C code for drawing graphic primitives to a framebuffer

2 Surac 5 7/11/2025, 12:47:59 PM
I have a framebuffer that must be seen as being slow. Also the cpu accessing the fb has no cache whatsoever to accelerate the memory access. I need c code for drawing thick lines with endcaps, thick circles, thick elipsoids and thick beizier curves. I have code to do all this 1 pixel wide, but I need code to draw them with a width without plotting over and over each pixel. I already have Bresenham implementation for lines, circles, ellipsis and beizier

Comments (5)

Asm2D · 53m ago
Then paint to a regular buffer and do a memcpy to the framebuffer that has no cache at the end of each frame, possibly only copying a region/tiles you want to update.

All the libraries that exist are designed to work like this.

mathiaspoint · 21h ago
You probably want to draw curves and polygons then fill them.

It's possible to imagine drawing extra thick lines by modifying the algorithm but the equivalent changes to a curve would leave gaps. I suppose you could figure out how eg boundary paths for beziers are calculated and transform your algorithm so each step draws to the boundary. It seems like more work for something less general than filling though.

mfabbri77 · 21h ago
You need to look at a 2d vector graphics library eg: Skia, Cairo, Agg, NanoVG, Blend2D, OpenVG (and many other, in no particular order).
Surac · 21h ago
Thanks. This librarys are so full of features that they literally burry the real drawing part. I had hoped for something more basic. No anti aliasing etc.
mfabbri77 · 20h ago
You have to look for "stroking": there are several ways to do it, in CPU you usually first perform a piecewise linear approximation of the curve, then offset each segment along the normals, add the caps, get a polygon and draw it.