SDL (Simple DirectMedia Layer)/Graphics/Rendering surfaces

In this section, we will modify our code to optimise  blitting using  and stretch our image to fullscreen using.

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

Optimising a for blitting
We can optimise a  for blitting, which in turn improves performance. is used to optimize images for faster repeat blitting. This is accomplished by converting the original and storing the result as a new surface.

We'll update our  function by using the following code.

Remember to destroy SDL object pointers using their corresponding functions, in this case.

Blitting a to fullscreen
We'll replace with. We'll write a static (and therefore private) function that blits a surface to fullscreen.

We'll have to initialise and declare a with the size of the entire window and blit the surface using dimensions of that.

We replace the blitting function in our :

You'll notice that we're not declaring a  pointer, it's a relatively small structure compared to   and the like, so we don't have to dynamically allocate memory for it.

|.