# Displaying an image on screen

**URL:** <https://fortran-lang.discourse.group/t/displaying-an-image-on-screen/5711>\
**Category:** Help\
**Created:** [May 1, 2023, 12:10pm UTC](https://fortran-lang.discourse.group/t/displaying-an-image-on-screen/5711 "2023-05-01T12:10:15Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [May 1, 2023, 9:08pm UTC](https://fortran-lang.discourse.group/t/displaying-an-image-on-screen/5711/14 "2023-05-01T21:08:36Z")

</div>

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](https://freeimage.sourceforge.io/), 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](https://fortran-lang.discourse.group/t/complex-arithmetic-significantly-slower-not-really/4569) 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](https://www.glfw.org/) 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](https://youtu.be/1mFXFtjqnRo). 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](https://github.com/vmagnin/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](https://www.fgrim.com/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](https://www.youtube.com/watch?v=a3IMEAFJbC8) 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](https://www.ir.isas.jaxa.jp/~cyamauch/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.

---

_[View the full topic](https://fortran-lang.discourse.group/t/displaying-an-image-on-screen/5711)._
