Simplest rudimentary canvas crate

I am trying to teach myself graphics programming from scratch. Thus, I would want to use a crate that only contains the most rudimentary canvas functions, e.g.:

  • Open a window that includes a canvas with a specified size (in pixels)
  • Draw a single pixel with a specified RGB color at a specified location on the canvas
  • (If the canvas does not redraw itself every frame automatically) A method to redraw the canvas.

In addition, it should be fairly performant (I know that this kind of code should likely run on the GPU, but currently I am more interested in the kind of abstractions I need to e.g. build an animation engine) and not include much else (as-in bloat-free). [1]

Is there a crate that includes this (and preferably, as I said, only this) functionality? I would also be open to not using any crate at all, but would prefer not having to resort to unsafe code. Again, this is not for production code, but educational purposes only.

[1]: I've used nannou before and it is the exact opposite of the thing I'm describing right now (almost 30MB deps and 1GB executable + build artifacts).

Not completely as minimal as you asked for, but macroquad - Rust could be an option that’s not too bloated. A clean build (including all dependencies) of the example takes less than 4s on my laptop.

1 Like

minifb is one of the simplest "framebuffer" crates I know of. it's very easy to use.

3 Likes

This looks like the best choice, thanks for the pointer.

softbuffer might be a better choice than minifb. The latter is older and has a lot of strange UX/platform bugs (the way it handles window resize, for instance). The former just needs something like winit for platform support.

That's probably true. I've almost spent an hour today trying to figure out why opening a window crashed every time (checking the X11 C documentation for why thus specific method returns a null pointer, etc.) only to find out I had accidentally misspelled my locale suffix during installation (UTF_8 instead of UTF-8).

However my goal is not creating a suitable or practical library but instead learning, and this minor interruption was likely helpful in that regard. I am also trying to - and I know this is an ambitious goal for GUI programming - become, in the end, completely "dependency free" apart from raw X11 FFI calls, and I think minifb even helps in being particularly simple and "unfriendly", architecture-wise.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.