GLFW returning the wrong GL_VERSION

2019-08-07 16:57发布

问题:

In GLFW I'm setting OpenGL context version via:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

However when I print it to the console after glfwMakeContextCurrent(window); and glewInit(); via:

Log::brightWhite("OpenGL version:\t");
Log::white("%s\n", glGetString(GL_VERSION));
Log::brightWhite("GLSL version:\t");
Log::white("%s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));

I get the following:

Why is it 4.3 and not 2.0?

回答1:

Because the implementation is free to give you any version it likes, as long it is supporting everything which is in core GL 2.0. You typically will get the highsest supported compatibilty profile version of the implementation. There is nothing wrong with that.

Note that forward and backward compatible contexts and profiles were added in later versions, so when requesting a 1.x/2.x context, this is the behavior you should expet. Note that on OSX, GL 3.X an above is only supported in core profile, so you will very likely end up with a 2.1 context there.