Using SDL2, is there a way to determine at runtime whether the application is using OpenGL, OpenGLES, or DirectX?
EDIT: If there is a way to figure it out without using the SDL2 API, I'm willing to throw that code into my project.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
In SDL2 the creation of the window is separate from the rendering environment used to draw into that window. So, while you might pass "SDL_WINDOW_OPENGL" to SDL_CreateWindow(), this simply states that the window should support rendering from an OpenGL context later down the line and doesn't actually create an OpenGL context at that point. So, from SDL_GetCurrentVideoDriver() I would expect only something like "windows", "x11" or "psp" due to the fact that this is the module used for handling just the window system and the final blitting of whatever the renderer draws to the screen.
Assuming that you're using a Renderer to draw 2D content to the screen - at the point you create a Renderer a DirectX or OpenGL context will actually be created for the renderer. After this point, you should be able to query the Renderer you have created for the actual driver being used. This is untested - so might need some tweaks, but I think it should give you more useful information than what you're currently getting.
/// ... Create Window ... SDL_Renderer *renderer = SDL_CreateRenderer(sdlWindow, -1, 0); SDL_RendererInfo rendererInfo; SDL_GetRendererInfo(renderer, &rendererInfo); std::cout << "Renderer: " << rendererInfo.name << std::endl;
You can request that SDL uses a given driver by setting SDL_HINT_RENDER_DRIVER like so...
But this is only a hint so it's not guaranteed. However, as the possible values for this hint are listed as 'direct3d, openGL, opengles2, opengles, software' I expect these to be the name values you would get back from the above SDL_GetRendererInfo call.
Hope this helps. Apologies if I'm barking up the wrong tree or this doesn't work as expected. Just thought I would throw a suggestion out there before heading to bed!
Once upon a time there was Google.
Now this seems to be what you are looking for:
const char* SDL_GetCurrentVideoDriver(void)
Returns the name of the current video driver or NULL if no driver has been initialized.