Simple X Graphics: An Incomplete Survey
Quick, what's the simplest way to put some graphics on the screen under X? I wasn't sure either, so I decided to try a few different approaches, all from C of course. Since it doesn't really matter what we draw, I cloned the classic "Boxes" demo from the early Amiga days.
Enjoy!
xcb
- complexity from okay (dis/connect) to insane (handling window close)
- documentation extremely spotty (and horribly out-of-date in places)
- requires familiarity with nearly all of the underlying protocols
- mask/values APIs are very brittle (order-dependent!)
- cookie/reply and cookie/check APIs somewhat painful (async hell?)
sdl
- complexity quite reasonable, just a lot of flags to look through
- documentation quite reasonable, includes (correct!) examples as well
- lots of valgrind issues (not just leaks!) in the library, pretty sad
gtk
- complexity moderately convoluted throughout, often 12 ways of doing something and little to help decide; lots of layers (glib, gdk, gtk, cairo)
- documentation reasonable, lots of it however (maybe too much?) and lots of (slightly) different versions; return values sometimes strangely absent; often hard to find the correct callback prototype
- the idle/tick combination is actually somewhat cute for real-time graphics
- threading implications are not clear at all but I didn't run afoul of that
- entire design seems leaky as valgrind is quick to point out
x11
- complexity is moderately convoluted, but maybe not quite as bad as GTK; the API definitely shows its age though
- documentation is voluminous although scattered around the web and often on sites from the late 1990s; details are often missing, for example what an error handler should return
- it's not entirely clear when certain things can be freed and how they should be; valgrind detect leaks although the sanitizers don't seem to