SDL (Simple DirectMedia Layer)/Basics/Creating a window

In this section, we will demonstrate how to create and destroy basic SDL windows. The following code will create a window called "SDL Example", 800 by 600 pixels in width and height respectively, and print it on the screen for 3000 miliseconds.

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

Setting up data
In order to create the window, we need to specify its height and width. In this case we define the global constants using a macro. We'll make the width 800 pixels long and the height 600 pixels high.

In this program, we will have to pause the SDL subsystems to let the window stay open. We'll define the delay to be 3000 milliseconds.

In C, it's a good idea to initialise your variables first in order to understand when and how they are being used. In this case, we initialise a  pointer called. In SDL, almost all objects are initialised as pointers.

Creating the window
In order to create the window, we need to use the  function and set some parameters too.

You can learn more about  in the SDL Wiki.

Using
In the example code, we used the function  in order to pause the SDL subsystems for a variable amount of time in milliseconds and allow the window to be shown on the screen whilst it is open. In this case, the pause is defined with the  macro as being 3000 milliseconds.

You can learn more about  in the SDL Wiki.

Destroying the window
In order to close the window and free memory, we must destroy the window. Destroying  is much simpler than creating it.

You can learn more about  in the SDL Wiki.

|.