弹出SDL窗口,但是它是空白的并且完全没有响应

时间:2019-01-24 01:54:50

标签: c++ sdl

我100%确定已将SDL库设置为正常工作

#include <iostream>
#include <SDL.h>
using namespace std;

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

    // Initializing SDL

    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window *window = 0;

    // Creating the window       

    window = SDL_CreateWindow("Hello World", SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED, 640, 480,SDL_WINDOW_SHOWN);
    // Just so I can see the window because it goes away immediately.    

    SDL_Delay(5000);

    SDL_Quit();

    return 0;
}

1 个答案:

答案 0 :(得分:2)

创建窗口后,需要使用SDL_PollEvent处理事件。代替SDL_Delay(5000),执行以下操作:

    // ... setup (SDL_Init, SDL_CreateWindow, etc.)
    SDL_Event event;
    for(;;) {
        while(SDL_PollEvent(&event)) {
            switch(event.type) {
                case SDL_QUIT:
                    goto done;
            }
        }
    }
done:
    SDL_Quit();
    return 0;