SDL2 - Check if OpenGL context is created

你离开我真会死。 提交于 2019-12-05 08:28:56

SDL2 does not in fact create an OpenGL context without you asking to make one. However, if you ask it to create an OpenGL context when OpenGL doesn't work at all, SDL2 likes to, erm, freestyle a bit. (The actual reason is that it does a bad job in error checking, so if X fails to create an OpenGL context, it assumes that it's because a context was already created)

So, to answer the third question ("how do I bypass this issue"), you have to fix OpenGL before attempting to use it. Figures, right?

To answer the first and second, well, no API call that I know of... but you can do it a slightly different way:

SDL_Window* window = NULL;
SDL_GLContext* context = NULL; // NOTE: This is a pointer!

...

int main(int argc, char** argv) {
    // Stuff here, initialize 'window'

    *context = SDL_GL_CreateContext(window);

    // More stuff here

    if (context) {
        // context is initialized!! yay!
    }

    return 2; // Just to confuse people a bit =P
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!