The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Confusion about GL Core Profile and testing for versions.
arkiruthis


Joined: 14 Dec 2014
Posts: 1
Hi everyone. I'm a little confused about the correct procedure for getting the correct implementation of OpenGL across platforms.

I had expected that SDL_GL_GetAttribute() with SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION would return 4 and 4 respectively (as OpenGL 4.4 is the implementation listed as supported on my ATI Driver info).

However, I consistently get OpenGL 2.1 returned by default each time. However, I can request up to 4.4 by setting those attributes and creating a GL Context successfully.

At the moment, I keep attempting to create a GL Context until failure:
Code:

bool FindCurrentGLVersion(SDL_GLContext& glContext, SDL_Window* window) {
   int majorV = 1;
   int minorV = 1;
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorV);
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorV);

   do { // Keep probing SDL_GL_CONTEXT_MAJOR_VERSION until failure
      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorV);

      if (glContext = SDL_GL_CreateContext(window)) {
         SDL_GL_DeleteContext(glContext);
         majorV++;
      }
      else {
         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, --majorV); // Step back 1 version from failure
         printf("Got as far as Major GL Version %d. \n", majorV);
         do { // Keep probing SDL_GL_CONTEXT_MINOR_VERSION until failure
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorV);

            if (glContext = SDL_GL_CreateContext(window)) {
               SDL_GL_DeleteContext(glContext);
               minorV++;
            }
            else {
               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, --minorV); // Step back 1 version from failure
               printf("Got as far as Minor GL Version %d. \n", minorV);
               break;
            }
         } while (true);
         break;
      }
   } while (true);

   if (!(glContext = SDL_GL_CreateContext(window))) {
      printf("Failed to Create GL Context. %s\n", SDL_GetError());
      return false;
   }
   return true;
}


This is certainly a sledgehammer-meet-walnut approach... but it works and returns 4.4 consistently each time.

I'm certain I'm missing a more elegant way of probing for this information. Smile