sdl2实现窗口管理

发布时间 2023-04-23 11:06:25作者: linux星

#include <SDL2/SDL.h>
int main(int argc, char* argv[]) {
    // 初始化SDL2
    SDL_Init(SDL_INIT_VIDEO);
    // 创建窗口
    SDL_Window* window = SDL_CreateWindow(
        "SDL2 Window",             // 窗口标题
        SDL_WINDOWPOS_CENTERED,    // 窗口位置在屏幕中央
        SDL_WINDOWPOS_CENTERED,
        640,                       // 窗口大小为640x480
        480,
        SDL_WINDOW_SHOWN           // 窗口显示
    );
    // 等待窗口关闭
    bool quit = false;
    while (!quit) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                quit = true;
            }
        }
    }
    // 销毁窗口
    SDL_DestroyWindow(window);
    // 退出SDL2
    SDL_Quit();
    return 0;
}