We will perform the SDL3 installation on CodeBlocks 20.03 32-bit version.
To perform the installation of SDL 3.1.6 Stable ABI Preview on CodeBlocks 20.03 32-bit version, let's follow the steps below:
1. Let's open the main page of the SDL 3.1.6 Stable ABI Preview version by clicking here. Let's download the SDL3-devel-3.1.6-mingw.zip file by clicking the link shown below at the bottom of the page.
2. Let's open the downloaded file on our computer and copy the directories under the C drive to create a structure like this:
To create an SDL3 program, let's follow the steps below:
1. Let's create a new project by clicking File-New-Project from the main menu:
2. After selecting the Console application option in the window that appears, let's click the Go button:
3. In the window that appears, let's click on the Next button:
4. After selecting the C option in the window that appears, let's click the Next button:
5. In the window that appears, let's give a project name (SDL3_001), and click the Next button:
6. In the window that appears, let's click on the Finish button:
7. The created project appears in the compiler window.
8. After copying the codes below, let's paste the codes in the main.c file:
#include <SDL3/SDL.h>
int main(int argc, char* argv[])
{
SDL_Window *window; // Window pointer declaration
SDL_Init(SDL_INIT_VIDEO); // Init SDL3
// Create an application window with the following settings:
window = SDL_CreateWindow(
"SDL3 window", // Window title
640, // Window width
480, // Window height
SDL_WINDOW_OPENGL // Flag
);
// Checks whether the window was created successfully.
if(window == NULL) {
SDL_Log("Window can not be created!: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(3000); // Delay the execution of the program for 3000 milliseconds.
// Close and destroy window
SDL_DestroyWindow(window);
// Exit SDL
SDL_Quit();
return 0;
}
To create an SDL3 program, let's follow the steps below:
1. Click on Project - Build options from the main menu to open the project options window:
2. In the window that appears, while the SDL3_001 option is selected on the left side (In this case, the operations performed are valid for both Debug and Release options), let's add the dll file to the project by adding the -lSDL3.dll statement to the Other linker options section of the Linker settings tab:
3. In the Search directories tab, in the Compiler tab, let's include the SDL3 include directory in the project by following the order shown in the following graphic:
4. In the Linker tab of the Search directories tab, let's include the SDL3 lib directory in the project by following the order shown in the following graphic:
5. To solve problems that may occur with the .dll file while the program is running, in the Compiler settings tab, in the Compiler Flags tab, select the first two or only the third option shown below:
6. In order to prevent the console window from appearing when the program is running, let's click on the Project - Properties option from the main menu and select the Type value in the Build targets tab as GUI Application in the window that appears:
7. When we compile the program, a file with an .exe extension is created in the debug directory. However, when we want to run it, it gives an error because there is no .dll file. Let's copy the SDL3 main dll file SDL3.dll to the directory where the .exe file is located:
8. When we run the program again, a window similar to the one below will appear and disappear after 3 seconds: