Which version does glGetString(GL_VERSION) get?

Does glGetString(GL_VERSION) get the maximum supported version for your system, or the version for your current context?

I know that you need to create a context in order for glGetString() to work, so that is what made me wonder if it was the current context or the highest available.

2

2 Answers

From the spec (copied from 3.3 spec document):

String queries return pointers to UTF-8 encoded, NULL-terminated static strings describing properties of the current GL context.

So it's the version supported by the current context. There's a subtle aspect if you're operating in a client/server setup:

GetString returns the version number (in the VERSION string) that can be supported by the current GL context. Thus, if the client and server support different versions a compatible version is returned.

The way I read this, it will return the minimum between the client and server if the two versions are different.

It's generally easier to use glGetIntegerv() to check the version. This way, you don't have to start parsing strings, and you can also get additional detail:

GLint majVers = 0, minVers = 0, profile = 0, flags = 0;
glGetIntegerv(GL_MAJOR_VERSION, &majVers);
glGetIntegerv(GL_MINOR_VERSION, &minVers);
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (profile & GL_CONTEXT_CORE_PROFILE_BIT) { ...
}
if (profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) { ...
}
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) { ...
}
0

The current context, it is a valid way to query what context you're currently rendering under.

See:

glGetString: return a string describing the current GL connection

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like