eugene.chepurnykh's picture

Get OpenGL version before Application.Run.

Does anybody knows, is it possible to get OpenGL version before Application.Run.
There is a requirement - check OpenGL version before application run. Who knows any tricks for that?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

To check the OpenGL version you need to create an OpenGL context. To create an OpenGL context, you need to create a window.

Possible solutions (both should work but I have tested neither):

  • Create a GLControl, query the version and destroy the control before you call Application.Run.
  • Create a NativeWindow, create a GraphicsContext using its WindowInfo, query the version and destroy both the context and the window prior to calling Application.Run.
eugene.chepurnykh's picture

To Fiddler:

Thank you. The answer was so simple.... I've tried to make WinGLControl, created context and windowInfo, executed MakeCurrent - but nothing good at the end.

This is fully working code.

        string version = string.Empty;
         try
            {
                GLControl control = new GLControl();
                version = GL.GetString(StringName.Version);
            }
            catch (Exception ex)
            {
                return false;
            }
the Fiddler's picture

Don't forget to dispose the GLControl and reclaim the resources it uses:

         string version = string.Empty;
         try
         {
             using (GLControl control = new GLControl())
             {
                 version = GL.GetString(StringName.Version);
             }
         }
         catch (Exception ex)
         {
             return false;
         }
eugene.chepurnykh's picture

Thank you again. Another part of rexeg mystery.
If somebody wants to parse Version of OpenGL I suggest next pattern:

           const string REGEX_VERSION_PATTERN = @"(\d+)\.(\d+)\.*(\d*)";
 
            Regex regex = new Regex(REGEX_VERSION_PATTERN);
            Match match = regex.Match(version);
            if (!match.Success || match.Groups.Count < 3)
            {
                return false;
            }
            int majourVersion = Convert.ToInt32(match.Groups[1].Value);
            int minorVersion = Convert.ToInt32(match.Groups[2].Value);
            if (majourVersion < GlobalConsts.OPENGL_LIB_MIN_MAJOUR_VERSION 
                && minorVersion < GlobalConsts.OPENGL_LIB_MIN_MINOR_VERSION)
            {
                return false;
            }