1
votes

I am trying to understand what glGetString(GL_VERSION) return as I get strange results when I use this function. Does this return the maximum opengl version supported by my GPU or the oepngl version of the current context created. According to Which version does glGetString(GL_VERSION) get? this return the opengl version of current context created but I think that is not the case. I want to forcefully create opengl context 3.1 (forward compatible), opengl context 2.0 and opengl context 1.1. Following are my observations

case 1: Using wglCreateContextAttribsARB to create context. I think it is returning the highest opengl context version Subcase 1:

int attribs[] =
{
    WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
    WGL_CONTEXT_MINOR_VERSION_ARB, 3,
    WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
    0
};
//glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.14.4264"

Subcase 2:

int attribs[] =
{
    WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
    WGL_CONTEXT_MINOR_VERSION_ARB, 1,
    WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
    0
};
//glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.14.4264"

Subcase 3:

int attribs[] =
{
    WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
    WGL_CONTEXT_MINOR_VERSION_ARB, 0,
    0
};
//glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.14.4264"

Subcase 4:

int attribs[] =
{
    WGL_CONTEXT_MAJOR_VERSION_ARB, 1,
    WGL_CONTEXT_MINOR_VERSION_ARB, 1,
    0
};
//glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.14.4264"

case 2: Using glut to create opengl context

Subcase 1:

glutInitContextVersion (3, 1);
glutInitContextFlags (GLUT_FORWARD_COMPATIBLE);
//glGetString(GL_VERSION) returns "3.1.0 - Build 10.18.14.4264"

Subcase 2:

glutInitContextVersion (2, 0);
//glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.14.4264"

Subcase 3:

glutInitContextVersion (1, 1);
//glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.14.4264"

Can someone explain this behaviour. I can post full code where I create the context. Also can someone please guide me how can I create opengl 3.1 (Forward compatible context), opengl 2.0 context and opengl 1.1 context both using glut and wglCreateContextAttribsARB?

1
How i understand for old OpenGL context (< 3.0) it returns max OpenGL version of your video card. But for in modern OpenGL you can setup profile. It means you can use only modern functions or only function of selected OpenGL version. In this case, it returns your selected version. - Unick
but when I use wglCreateContextAttribsARB with attributes for 3.1 forward compatible context, it still prints "4.3.0 - Build 10.18.14.4264". What you said makes sense for opengl 2.0 and opengl 1.1. I also tried to creare core context for opengl 3.3, but it sill shows opengl version 4.3. I have updated my question. please have a look - Pankaj Bansal
I think in case 1 you use wglCreateContextAttribs wrong. Because i see glut creates 3.1 correctly.Could you please add code? - Unick
yup I got the error in first case. So I should assume that what you said in first comment is right. For <3.0, it always shows highest version, but for context >3.0, it shows current context version. I hope what I just wrote is what you meant exactly in your comment. Right? - Pankaj Bansal

1 Answers

2
votes

glGetString(GL_VERSION) returns the version of the current context. This often can be (but is not always) the highest supported version.

The reason for this is in the opengl specification:

The attribute names WGL_CONTEXT_MAJOR_VERSION_ARB and WGL_CONTEXT_MINOR_VERSION_ARB request an OpenGL context supporting the specified version of the API. If successful, the context returned must be backwards compatible with the context requested.

It then goes on to state that if you request a version below 3.0, then it the context can be a version 3.2 or greater provided that they are in compatibility profile. It's giving you 4.3.0 just because it should work.

It can also give you the core version of any GL past 3.2 if you request 3.1. If you request 3.2 or newer, it can also give you any later version provided no features have been removed. Currently this is none as far as I'm aware.

https://www.opengl.org/registry/specs/ARB/wgl_create_context.txt