SDL (Simple DirectMedia Layer)/Graphics/Rendering other image formats

Rendering other image formats requires the use of another SDL library:. However, the process of rendering different image formats is very much the same as rendering BMP images. In this section, we'll demonstrate how to render a PNG file onto a window.

You can download the source code of this section in this GitLab repository. All source code is stored in this group.

Importing the library
We'll import the  library, in , in the following fashion:

Initialising the image subsystem
Right after initialising the SDL subsytems, we would need to initialise the image subsystem using. Given the parameter, it returns   on success.

We'll want to render a PNG file so we would want to use the flag. There are other flags like  (check  for more information). To initialise multiple flags use the  OR operator, for example:

You'll also have to use to close the subsystem.

Since we're using, we have to use   in place of.

Loading the image
Loading the image is very simple, just use the function on a. Like with, we must use.

Remember, to make sure that the file path to the image is correct, i.e. ! We're rendering a PNG image!

|.