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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With