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.
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...
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
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!
direct3d
.
\$\endgroup\$
Commented
Feb 10, 2016 at 10:28
SDL_SetHint()
before SDL_CreateRenderer()
, it will properly create "metal" one for me. Here is testing code gist.github.com/haxpor/c02a6ba98e3ff35800eeb3a4f4f5b0b4. Interested people can substitute value of "meta" to be others as needed and see the result.
\$\endgroup\$
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.
SDL_GetCurrentVideoDriver()
returns string windows
. When I tried to print all avalible "drivers", I got these three: windows
, dummy
and ` ` (empty string).
\$\endgroup\$
Commented
Aug 14, 2014 at 19:44
SDL_GetRendererInfo
might be for you. \$\endgroup\$