SDL window don't open in i3 window manager (Ubuntu)

Hi, im starting with SDL by this video Writing 2D Games in C using SDL by Thomas Lively - YouTube and stuck with opening a window. My window just dont open. I have switch to Gnome and SDL window work! But i really love tiling window manager and dont consider that i should use Gnome just because SDL work on it. What could be the problem? I also use Compton as a composite manager.

What error does SDL give you when the window can’t be created?

Dont have any errors. Program start as if it work properly (window set to be active 5 sec and terminal really frozen for this 5 seconds as if program is run and then return from frozen state).

Looking at the first window example, it’s normal that nothing shows up.

On some platforms you need to pump events for your window to show up. It is probably what the tutorial is headed towards, but you need an event loop:

bool running = true;
while(running) {
  SDL_Event ev;
  while(SDL_PollEvent(&ev) {
    switch (ev.type) {
      case SDL_QUIT:
        running = false;
        break;
    }
  }
}

If your replace the SDL_Delay(5000) with this, the window should show up. You can then close it like you close any other window.

I replace delay like this:

    //SDL_Delay(5000);

bool running = true;
while(running) {
  SDL_Event ev;
  while(SDL_PollEvent(&ev)) {
    switch (ev.type) {
      case SDL_QUIT:
        running = false;
        break;
    }
  }
}

And all work like before. Window open only with Gnome.

That’s really odd, I’d encourage you to open an issue on the GitHub issue tracker.

Here’s a full example you may want to run before opening the issue:

#include <SDL2/SDL.h>

int main(int, char **) {
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    SDL_Log("Failed to init: %s\n", SDL_GetError());
    return 1;
  }

  SDL_Window *win = SDL_CreateWindow("Example", SDL_WINDOWPOS_UNDEFINED,
                                     SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);

  if (win == nullptr) {
    SDL_Log("Failed to create window: %s\n", SDL_GetError());
    SDL_Quit();
    return 1;
  }

  bool running = true;
  while (running) {
    SDL_Event ev;
    while (SDL_PollEvent(&ev)) {
      switch (ev.type) {
      case SDL_QUIT:
        running = false;
        break;
      }
    }
  }

  SDL_DestroyWindow(win);
  SDL_Quit();

  return 0;
}

It can be compiled with the following command: g++ $(pkg-config sdl2 --cflags --libs) example.cpp

If it still does not work, here is the information you want to include in your issue:

  • Your distro, your display server (Xorg/Wayland), your Desktop Environment, and Window Manager.
  • What SDL version you are using, you can get it with the pkg-config sdl2 --modversion.
  • The sample code above to reproduce your issue.

This tutorial headed for using SDL with C, not C++. And using Clang - C compiler in makefile accordingly.