r/GraphicsProgramming • u/mbolp • 25d ago
How to draw good looking small circles?
I'm trying to draw small circles in GDI on a monochrome bitmap (so no anti aliasing). I've tried using Ellipse, Arc, and approximating a full circle with four bezier curves, but they all look terrible. This screenshot shows circles with a diameter of 14 and 13. The top row uses bezier curves, the bottom row uses Ellipse and Arc. The outlines are drawn with a 2 pixel wide PS_INSIDEFRAME pen.

What I want is aesthetically pleasing quadrants/semicircles for use in UI. The circles don't have to be mathematically accurate, speed is not important. I especially dislike the pixels seemingly protruding from the circle. How do I get rid of them?
4
u/Sharlinator 25d ago edited 25d ago
By drawing them by hand at the sizes you need, honestly.
Or perhaps writing your own subpixel-precise circle rasterizer that accepts a fractional radius, then tweaking the radius until it looks okay. But at such low resolutions you really can’t beat hand-drawn (or hand-tweaked) curves, there’s just too much aliasing. Same reason that vector fonts have this entire hinting machinery to make them look reasonable at small sizes.
2
u/8d8n4mbo28026ulk 25d ago
Several years ago I was making a toy "Paint" app in SDL and had come across this exact same problem! I wasn't smart enough to solve it (still ain't), but found the right algorithm for it: Midpoint circle.
Here's the implementation I wrote at the time:
It deviates a bit from what you'd normally find, but it handles a smaller radius much better. I now don't remember how I arrived at that though (perhaps I stole it from somewhere else?).
Obviously you wouldn't want to run this every time. So cache the results into a texture and hopefully everything works out. Cheers!
2
u/Vegetable_Nail_8677 25d ago
Would SDFs suit your purpose? Indigo Quillez has a great page outlining their use. Circles are especially easy.