SDL_GL_SetAttribute() not returning an error

Before I create an OpenGL context, I’m setting the major and minor versions to 3.2. Apparently the Android Studio emulator doesn’t support it, but SDL wasn’t returning an error. Is this expected behavior? It does the same thing on Windows if I use a random value like 9.9. It’s just returning 0/success. SDL_GL_GetAttribute() is returning whatever value I give it.

So, if this is the expected behavior, how can I check what version the device supports?

More likely is that I’m setting this value incorrectly. Right now, my code looks like this:

main() {

   auto * window = SDL_CreateWindow();
   if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 9) != 0) {
      // this never happens


   auto majorVersion = int{ 0 };
   SDL_GL_GetAttribute(SDL_GL_CONTECT_MAJOR_VERSION, &majorVersion); // returns 9

I hadn’t thought about this when I was running my game on Windows and my phone, but once I switched it to an Android emulator, I’m getting weird problems that I think are caused by an unsupported version of GLES. (Checking the emulator shows that it only supports 2.0).


1 Like

Read this post!

Thanks for the reply! I’ve been focusing on other parts of my engine/game.

Reading through that, it seems like it’s more targeted for a situation where OpenGL itself isn’t available on the system. Am I missing something obvious in that thread? A quick Google search reveals people asking the broader version of my original question. (That is, querying the latest available version but without using SDL.)

GLFW’s approach seems similar to what your linked thread described; that is, request the minimum version required and then use glGetString(GL_VERSION), but this seems an unnecessary workaround given SDL’s documentation for SDL_GL_SetAttribute():

Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information. […] You should use SDL_GL_GetAttribute() to check the values after creating the OpenGL context, since the values obtained can differ from the requested ones.

SetAttribute() is returning 0 even when I request a nonexistent version, and GetAttribute() is returning the value I requested rather than one that OpenGL supports. In summary, I don’t understand why SetAttribute() isn’t returning an error if it’s failing or why getAttribute() isn’t returning the actual version if it’s succeeding.

Perhaps this is a similar issue? It seems like people have been having some trouble setting/getting the OpenGL version in SDL.


Report this issue to the Khronos group!