SDL2 - check if OpenGL context is created

I am building an application using SDL2 and OpenGL, and it worked perfectly on three different computers. But on another computer (updated linux archive) this is not the case, and it crashes with this error:

OpenGL context already created 

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

If I can’t do this, how can I get around this?

+6
source share
1 answer

SDL2 does not actually create an OpenGL context without requesting it. However, if you ask him to create an OpenGL context when OpenGL does not work at all, SDL2 is like, erm, freestyle a bit. (The actual reason is that it does a poor job of checking for errors, so if X does not create an OpenGL context, it assumes this is because the context has already been created)

So, to answer the third question ("how to get around this problem"), you must fix OpenGL before trying to use it. The numbers, right?

To answer the first and second, well, API API I know about ... but you can do it a little differently:

 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 } 
+3
source

Source: https://habr.com/ru/post/956518/


All Articles