如何在 Windows 7kl 上检查 OpenGL 版本
我使用的是 Windows 7。我正在其上使用 OpenGL 进行编程。但我发现有一些功能我可以使用。所以我想检查我系统上的 OpenGL 版本。 我使用下面的代码来检查它
const char* version = (const char*)glGetString(GL_VERSION);
但我得到一个空指针。如果我想升级我的 OpenGL,我该怎么办?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在询问您拥有哪个版本之前,您需要当前的 GL 上下文。
因此,首先,创建一个上下文,对其调用 wglMakeCurrent,然后您应该能够调用 glGetString。
报告的版本来自您已安装的驱动程序。您的硬件可以支持的 OpenGL 版本本身并不是“可升级的”(因为某些硬件功能将无法支持最新和最好的版本)。
因此,您能做的最好的事情就是升级您的驱动程序,但不要寄希望于它会带来更新的 OpenGL。
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.
最简单、最快的方法是使用诊断工具,例如 GPU Caps Viewer。
您还可以使用glGetString(GL_VERSION),但请记住,您将显示的版本是给定OpenGL上下文的版本 - 这不一定是您的GPU可以执行的最高版本。
但是,如果您使用默认设置创建上下文,您可能会在兼容性配置文件中获得尽可能高的 OpenGL 上下文,所以是的,此方法可能很有用。
另外,由于
glGetString(GL_VERSION)
引用给定的 OpenGL 上下文,因此您需要预先创建它。实际上,调用任何gl*
函数都需要 GL 上下文。事实上,升级驱动程序可能会为您提供更高的 GL 版本,但主要版本不太可能发生变化。例如,如果您发现自己支持 GL 3.1,则最新的驱动程序很可能会为您提供 GL 3.3,而不是 GL 4.0。
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.
在调用 glGetString(GL_VERSION) 之前,您需要创建 OpenGL 上下文 (WGL):
You need to create OpenGL Context (WGL) before calling glGetString(GL_VERSION) :
尝试使用以下代码,它对我有用:
确保您的程序中包含 string 和 iostream。
try to use the following code, it works for me:
Make sure that you include string and iostream in your program.