【问题标题】:SDL Window does not show even with Event Loop即使使用事件循环,SDL 窗口也不显示
【发布时间】:2020-04-27 06:22:50
【问题描述】:

我知道之前有人问过这个问题,但大多数时候答案只是添加延迟或事件循环。但是我添加了一个事件循环并且窗口没有显示。只有控制台。我在 Visual Studio 2019 中运行这个程序。

#include <iostream>
#include "GL/glew.h"

#define SDL_MAIN_HANDLED

#include "SDL.h"

int main() {

    SDL_Window* window;
    SDL_Init(SDL_INIT_EVERYTHING);

    //fenster erstellen
    window = SDL_CreateWindow("C++ OpenGL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_OPENGL);
    //opengl context setzen
    SDL_GLContext glContext = SDL_GL_CreateContext(window);

    bool close = false;
    while (!close) {

        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                close = true;
            }
        }

        if (close) {
            break;
        }
    }

    return 0;
}

【问题讨论】:

    标签: c++ window sdl


    【解决方案1】:

    您需要包含SDL_MainReady,因为您没有使用SDL_main

    here

    所以你的代码会像这样调整

    int main() {
        SDL_Window* window;
    
        SDL_SetMainReady();
        SDL_Init(SDL_INIT_EVERYTHING);
    
        ...
    
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多