Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL_Window not displayed in windowed mode in macOS

Tags:

c++

macos

sdl-2

Running the following code, I'm not able to view a window unless I set SDL_WINDOW_FULLSCREEN in SDL_CreateWindow. With any other settings, I can see the process running, but no window appears. I'd like to be able to create a windowed SDL_Window. Am I missing something?

Running macOS Sierra, SDL v2.0.7

#include <SDL2/SDL.h>

int main() {
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
        return 1;
    }

    SDL_Window *window = SDL_CreateWindow(
        "Title",
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        640,
        800,
        SDL_WINDOW_SHOWN
    );

    if (window == NULL) {
        SDL_Log("Unable to create window: %s", SDL_GetError());
        return 1;
    }

    SDL_Delay(5000);

    // Cleanup.
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}
like image 374
brianpmaher Avatar asked Nov 29 '22 22:11

brianpmaher


1 Answers

Can you try adding an event loop instead of a SDL_Delay?

bool quit = false;                                      
SDL_Event e;                                            
while (!quit) {                                         
    while (SDL_PollEvent(&e)) {                         
        if (e.type == SDL_QUIT) {                       
            quit = true;                                
        }                                               
    }                                                   
}                                                       

So now I've tried your code on my Mac machine at work and it indeed does not show a window. Your code is not giving SDL enough time to even show a screen, it just goes to sleep and exits. With the event loop is showing a non-fullscreen non-maximized window.

like image 126
aram Avatar answered Dec 05 '22 20:12

aram