2016-06-16 7 views
-1

Я только сейчас изучаю SDL и загружаю библиотеки и добавляю их в свой компоновщик и т. Д. С помощью MinGW, и я пытаюсь запустить простую демонстрационную программу для отображения окна, и он не будет показывать вообще. Я не получаю никаких ошибок, окно просто не появляется.Окно SDL вообще не отображается

#include "SDL.h" 
#include <stdio.h> 

int main(int argc, char* argv[]) { 

SDL_Window *window;     // Declare a pointer 

SDL_Init(SDL_INIT_VIDEO);    // Initialize SDL2 

// Create an application window with the following settings: 
window = SDL_CreateWindow(
    "An SDL2 window",     // window title 
    SDL_WINDOWPOS_UNDEFINED,   // initial x position 
    SDL_WINDOWPOS_UNDEFINED,   // initial y position 
    640,        // width, in pixels 
    480,        // height, in pixels 
    SDL_WINDOW_OPENGL     // flags - see below 
); 

// Check that the window was successfully created 
if (window == NULL) { 
    // In the case that the window could not be made... 
    printf("Could not create window: %s\n", SDL_GetError()); 
    return 1; 
} 

// The window is open: could enter program loop here (see SDL_PollEvent()) 

SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example 

// Close and destroy the window 
SDL_DestroyWindow(window); 

// Clean up 
SDL_Quit(); 
return 0; 

}

+2

Ну на самом деле это работает прекрасно для меня – Zouch

ответ

2

Я просто проверил это на Linux и MinGW. Это может быть проблемой с блокировкой SDL_Delay, прежде чем окно получит возможность показать. Попробуйте добавить основной основной цикл, чтобы узнать, работает ли он. Это создаст пустое окно.

#include "SDL.h" 
#include <stdio.h> 

int main(int argc, char* argv[]) { 

SDL_Window *window;     // Declare a pointer 

SDL_Init(SDL_INIT_VIDEO);    // Initialize SDL2 

// Create an application window with the following settings: 
window = SDL_CreateWindow(
    "An SDL2 window",     // window title 
    SDL_WINDOWPOS_UNDEFINED,   // initial x position 
    SDL_WINDOWPOS_UNDEFINED,   // initial y position 
    640,        // width, in pixels 
    480,        // height, in pixels 
    SDL_WINDOW_OPENGL     // flags - see below 
); 

// Check that the window was successfully created 
if (window == NULL) { 
    // In the case that the window could not be made... 
    printf("Could not create window: %s\n", SDL_GetError()); 
    return 1; 
} 

// A basic main loop to prevent blocking 
bool is_running = true; 
SDL_Event event; 
while (is_running) { 
    while (SDL_PollEvent(&event)) { 
     if (event.type == SDL_QUIT) { 
      is_running = false; 
     } 
    } 
    SDL_Delay(16); 
} 

// Close and destroy the window 
SDL_DestroyWindow(window); 

// Clean up 
SDL_Quit(); 
return 0; 

} 
+0

я была такая же проблема с Mac OS Sierra _ (10.12.6) _ и основной цикл устранили эту проблему. Благодаря! – PantsMagee