How to check if an OpenGL extension is supported

Before using an OpenGL feature, you need to check that it is supported by your GPU drivers. It is an error to call functions that belong to an unsupported feature and doing so will result in undefined behavior.

For a core feature, i.e. all functions exposed directly by the GL class, it is sufficient to check the version string of the driver against the minimum version required by the feature. The minimum version is listed in the documentation tooltip of each OpenGL function.

// Retrieve the OpenGL version string. Do this once on startup.
string version_string = GL.GetString(StringName.Version);
int major = int.Parse(version_string.Split(' ')[0]);
int minor = int.Parse(version_string.Split(' ')[1];
Version version = new Version(major, minor);
 
// Create Version objects for each OpenGL feature you wish to use.
// You can find the minimum version for each feature in the
// documentation tooltips or in the OpenGL specification.
// For example, GL.GenFramebuffer() says in its documentation:
// "[requires v3.0]"
static class RequiredFeatures
{
    public static readonly Version FramebufferObject = new Version(3, 0);
}
 
// Before using a feature, check that it supported by the OpenGL driver
if (version >= RequiredFeatures.FramebufferObject)
{
    int fbo = GL.GenFramebuffer();
    ...
}

For an extension feature, i.e. functions exposed under the nested classes GL.Arb, GL.Ext, GL.NV etc, you must check that the required extension string is advertised by the driver.

// For OpenGL 3.0 and higher
Dictionary<string, bool> extensions =
    new Dictionary<string, bool>();
int count = GL.GetInteger(GetPName.NumExtensions);
for (int i = 0; i < count; i++)
{
    string extension = GL.GetString(StringNameIndexed.Extensions, i);
    extensions.Add(extension, true);
}
 
// For OpenGL 2.1 and lower
Dictionary<string, bool> extensions =
    new Dictionary<string, bool>();
string extension_string = GL.GetString(StringName.Extensions);
foreach (string extension in extension_string.Split(' '))
{
    extensions.Add(extension, true);
}
 
// Check that an extension is supported before using it.
// The required extension string is reported in the
// documentation tooltip for each extension function.
// For example, GL.Ext.GenFramebuffer says:
// [requires: EXT_framebuffer_object]
if (extensions.ContainsKey("GL_EXT_framebuffer_object"))
{
    int fbo = GL.Ext.GenFramebuffer();
    ...
}

More information can be found in the OpenGL wiki: https://www.opengl.org/wiki/Get_Context_Info