SDL2 - 检查是否创建了OpenGL上下文 [英] SDL2 - Check if OpenGL context is created

查看:306
本文介绍了SDL2 - 检查是否创建了OpenGL上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SDL2& OpenGL,它在3台不同的计算机上工作得很好。但是在另一台计算机(一个更新的arch linux)上,它不会,并且崩溃与这个错误:

I am creating an application using SDL2 & OpenGL, and it worked fine on 3 different computers. But on another computer (an updated arch linux), it doesn't, and it crashes with this error:

OpenGL context already created

所以我的问题是:如何检查OpenGL上下文是否已经创建?

So my question is: How do I check if the OpenGL context has already been created? And then, if it is already created, how do I get a handle for it?

如果我不能这样做,如何绕过这个问题? p>

If I can't do this, how do I bypass this issue?

推荐答案

SDL2 实际上创建了一个OpenGL上下文,然而,如果你要求它创建一个OpenGL上下文,当OpenGL根本不工作,SDL2喜欢,自由式一点点。 (实际的原因是它在错误检查中做错了,所以如果X无法创建一个OpenGL上下文,它假设它是因为上下文已经创建)

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)

因此,要回答第三个问题(如何绕过这个问题),您必须在尝试使用它之前修复OpenGL。数字,对不对?

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

要回答第一和第二,好吧,没有我知道的API调用...但你可以做一个稍微不同的方法: p>

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
}

这篇关于SDL2 - 检查是否创建了OpenGL上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆