Suggestions for a simple, portable, graphics library?

I’m working on a little side project where I need to do some simple, cross-platform game-like graphics. Really simple: I want to be able to draw some colored lines, and splat out rotated images. But I’d also like this to be reasonably efficient, and reasonable easy to use.

And, ideally, I’d love for something that was portable to Windows.

I’ve done just a bit of poking around, and it wasn’t quite clear to me what the right choice was.

  • I looked at tsdl and tgls, but it wasn’t clear to me with either of them how to rotate a texture. Maybe I’m just missing something? Also, I found tgls a little hard to navigate, since I haven’t used opengl for 20 years. I feel like rotation has to be in there, but searching for “rotate” in the docs comes up empty, and I couldn’t find any good examples. The portability story here seemed hopeful.
  • I looked at OCaml’s venerable Graphics library. Super easy to use, not sure about the portability story. No efficient way of rotating images, though.
  • wall. Seems to have all the capabilities, not sure about the portability story.
  • web. Portable, though I’d need to have a more complex setup for users, where the native OCaml program would run a web-server that would communicate to the OCaml UI, since I need this to be a native app. Feels extra complicated.

Anyway, does anyone have any suggestions on what path to take? Am I missing any options?


I have never really used the SDL 2D support but it could have you covered. This should allow you to rotate a texture.

The OpenGL of today bares little ressemblance to the one you knew, this is the hello world nowadays. Rotation is there under the form of matrices that you access in shaders but you also need to deal with defining, compiling and feeding those with data which brings quite a bit of boiler plate (see the example).

Also on macOS, OpenGL “the API”, seems to be on the way out. I suspect the 2D SDL API may be a better bet since it will likely keep you with a compatibility, hardware accelerated layer.

If you can lift the native constraint, the web would still be my first shot, nothing beats it’s ease of installation.


That is an impressive Hello World.

I’ll give Tsdl a shot. Thanks for the pointer on rotations.


I want to second the recommendation of Tsdl. The 2D api + opengl context for “advanced” things should cover your needs. Performance shouldn’t be a problem.

I have used it with great success recently here as part of a performance:
(Content warning: horror movie imagery)
(Sorry for the twitter link. I don’t have a linkable video of it anywhere else)

1 Like

You surely can’t go wrong with SDL/tsdl.

Another alternative could be raylib, a gamedev library created mainly for teaching. The lib has tons of examples, of which a few are already translated to the OCaml bindings. There is also an example for rotating a texture. And it works on Windows.


I’ve long wished that Reprocessing would be ported to OPAM. Currently that’s not the case, and I’m not sure it’s even installable from esy, but it’s exactly the kind of thing @Yaron_Minsky is looking for.

1 Like

Looks like I’m a little late to the thread but I think reason-skia is an awesome choice. It should provide all the Skia primitives which are pretty similar to the JavaScript canvas API and it’s specifically focused on 2d graphics. It’s also got great cross-platform support. It’s being very actively developed as part of Revery.

It’s also possible to use the Skia bindings through Revery to take advantage of the rest of Revery’s features: Revery exposes Skia as part of its Canvas API. This is really nice because you can avoid all the window setup stuff you’d have to do with SDL or raw OpenGL.


If you excuse the Reason-syntax, here’s a “Hello World”-example for Revery using Canvas.


Yeah, SDL already uses the Metal rendering backend by default on macOS. Can be confirmed using this function.

Before false information starts to spread could you please make precise what is “too out of date” in tsdl ?

A few things that made it in SDL 2.0.7-11 may not be in (but some of these things were actually contributed, I don’t remember exactly which ones).

But given the surface of the API and as you can witness by reading the linked release notes if something is missing that’s not much and rather trivial to add.


Thanks for letting me know – I definitely stand corrected on this! Will edit the original post