Displaying an image on screen

There are many (and I mean many) ways to do image creation, manipulation, rendering, and saving in files. Trust me, I could go on for ages and I wouldn’t cover them all. I will just mention the ways I consider the best ones, in no particular order.

  • You will need an image creation/manipulation library, at the very least. There any many libraries for this, but after quite some research, I ended up with FreeImage, in my opinion the best library for this task. You can create images and save them in many image formats. The image I posted in this thread was actually created with a Fortran program using my bindings for FreeImage. Now, if you want to display that image - either on-the-fly or once it is fully created - you will need also need OpenGL, together with a library to create windows with OpenGL contexts and user interaction. GLFW is the most advanced library I am aware for this task. I use my own Fortran bindings for all the above.
    This solution is the most complicated, but also the one that provides the most functionality and flexibility - which you may or may not need.
  • The SDL API is a great solution. @vmagnin and @milancurcic already mentioned existing Fortran bindings for SDL2, but for many reasons I use my own Fortran library for this. My implementation provides (almost) complete Fortran bindings for SDL2, together with a higher-level API to facilitate programming in SDL2. You can watch a demo of my library doing image manipulation with effects here. Whichever you will use should work for what you want.
    SDL is a way simpler solution, compared to the one above, but has less functionality. Unless you want really fancy effects, it is much more than enough for what you want to do though.
  • GTK with cairo and friends is also a great solution, and there are well-maintained Fortran bindings for this, namely gtk-fortran. You need to have a decent knowledge of the GTK4 API for that - which I am still learning, so I can’t comment much. From what I know so far though, this seems to be of intermediate difficulty programming-wise, and has the advantage you won’t need bindings for this and that, they are all-in-one.
  • A way overlooked library for what you want to do (and much more) is MGRX. It is a well-written library, and I had no issues to port it in Fortran. It is also well-maintained and regularly updated. Some time ago I uploaded a demo of image manipulation in Fortran using MGRX in a long-time-obsolete computer.
    I will rate this solution as the simplest one, programming-wise. MGRX API is clean and simple (simpler than SDL’s,) at the cost of slightly slower performance - but you probably won’t even notice that. Afterall, I can do image animations in a “potato computer” using MGRX.

Like I said, there are many other solutions as well. The one I would very much wanted to include in the list is EGGX/ProCall, because it has its own “native” Fortran API. Unfortunately, I can’t recommend it for what you want to do, because its image rendering is bare-bones basic.

3 Likes