I am using the Windows 7. I am programming using the OpenGL on it. But I found that there are some features I can use. So I want to check the version of the OpenGL on my system. I use the code below to check it
const char* version = (const char*)glGetString(GL_VERSION);
But I get a null pointer. And if I want to upgrade my OpenGL, what should I do?
The easiest and fastest way is to use a diagnostic tool like GPU Caps Viewer.
You can also use
glGetString(GL_VERSION)
but remember that the version which you'll have displayed is the version of a given OpenGL context - which is not necessarily the highest your GPU can do. However, if you create the context with default settings, you'll probably get the highest possible OpenGL context in compatibility profile, so yes, this method can be useful.Also, as the
glGetString(GL_VERSION)
refers to a given OpenGL context, you need to have it created beforehand. Actually, a GL context is required to call anygl*
function.Indeed, upgrading the drivers may give you a higher GL version, but it's unlikely that the major version would change. For example, if you'd find yourself having support for GL 3.1, it's very likely that the latest drivers will give you GL 3.3, but not GL 4.0.
You need to create OpenGL Context (WGL) before calling glGetString(GL_VERSION) :
try to use the following code, it works for me:
Make sure that you include string and iostream in your program.
You need a GL context current before you can ask which version you have.
So first, create a context, call wglMakeCurrent on it, and you should be able to call glGetString after that.
The version that gets reported is coming from the driver that you have installed. The OpenGL version that your hardware can support is not itself "upgradable" (because some hardware features will be missing to support the latest and greatest).
So the best you can do is upgrade your driver, but don't get your hopes to high it will result in a newer OpenGL.