To fix this issue, it appears that `SDL_PollEvent()` may need to be called in order to make the window appear and this behaviour can be dependent on the operating system used to run the program. Adding a simple `while()` loop to keep the program running does not appear to be sufficient to keep a window open. This issue is discussed here: [Why does my window only get shown after I use SDL_PollEvent()?](https://stackoverflow.com/questions/63406428/why-does-my-window-only-get-shown-after-i-use-sdl-pollevent)
The revised code is as follows:
```
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
// Variables used by the event loop
SDL_bool quit = SDL_FALSE;
SDL_Event e = { 0 };
// Initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("SDL_Init Error: %s\n", SDL_GetError());
return 1;
}
// Create a window
SDL_Window *win = SDL_CreateWindow("Hello, SDL2!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if (win == NULL) {
printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
// Create a renderer
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == NULL) {
SDL_DestroyWindow(win);
printf("SDL_CreateRenderer Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
// Set the draw color to blue
SDL_SetRenderDrawColor(ren, 0, 0, 255, 255);
// Clear the window
SDL_RenderClear(ren);
// Present the window
SDL_RenderPresent(ren);
// Event loop
while (!quit) {
while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_QUIT:
quit = SDL_TRUE;
break;
default:break;
}
}
}
// Clean up
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}