Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which version does glGetString(GL_VERSION) get?

Tags:

opengl

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.

like image 740
sm81095 Avatar asked Oct 25 '25 02:10

sm81095


1 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) {
    ...
}
like image 86
Reto Koradi Avatar answered Oct 28 '25 02:10

Reto Koradi