用SDL写个Hello World


const int WIDTH = 600;
const int HEIGHT = 600;
void SDLExample() {
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        std::cout << "初始化失败" << std::endl;
    }
    SDL_Window *window = SDL_CreateWindow("Skia + SDL"
            ,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED
            ,WIDTH,HEIGHT,SDL_WINDOW_ALLOW_HIGHDPI);
    if (window == nullptr){
        std::cout<< "创建Window失败" << std::endl;
    }

    SDL_Event windowEvent;
    while (true){
        if (SDL_PollEvent(&windowEvent)){
            if (windowEvent.type == SDL_QUIT){
                std::cout << "终止程序" << std::endl;
                break;
            }
        }
    }
    SDL_DestroyWindow(window);
    SDL_Quit();
}

基本的步骤

  1. 初始化
  2. 创建Window
  3. 监听输入事件
  4. 监听到关闭事件的时候销毁Window并离开

源码

https://github.com/jiangkang/renderer-dog


文章作者: 姜康
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 姜康 !
评论
  目录