HACKER Q&A
📣 skywal_l

Any minimalist cross-platform low-level C graphic library?


I often find myself needing a canvas to experiment things. In the Javascript world it's pretty easy: open a tab, open the dev console, append a to your DOM and that's it.

What could be the equivalent in C ?

My requirements are: 1. Can create a window and push pixel to it. 2. No dependencies, especially not OpenGL. 3. Some drawing capabilities (lines, shapes, 2d transformation). 4. Can wait for user inputs (in a blocking way ideally). 5. Appreciated: Single header. 6. Optional: Some text drawing capability.

Note that I am not looking for a GUI/widget library like Nuklear. I just need to push pixels into a window. The obvious closest would be SDL (or something like raylib) but it depends on OpenGL and offer way more than I need (3d capabilities, sound, etc).

Although minimalist, I still want that library to handle the underlying window system (X11 on linux, Windows shell, Quartz) so I don't worry about portability.


  👤 strangecasts Accepted Answer ✓
It's not been maintained for a while, but TinyPTC (https://sourceforge.net/projects/tinyptc/) might be worth a look - it's specifically intended for small demos, does not depend on OpenGL (aside from being an option on Linux), and will let you "push pixels" to a window.

I would urge you to reconsider SDL though - it's going to be a lot easier to port to other platforms, and it's going to be maintained for a long time.

e: You don't have to use SDL's audio/rendering subsystems either - it is possible to just treat it as a pure window/event management library.


👤 chunkles
I don't know if it meets all your criteria, but you might look at imgui, specifically cimgui which is just the autogenerated c-api wrapper for imgui.

https://github.com/ocornut/imgui https://github.com/cimgui/cimgui