我怎么知道我的系统支持哪个opengl版本 [英] How can i know which opengl version is supported by my system

查看:573
本文介绍了我怎么知道我的系统支持哪个opengl版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个非常基本的C ++代码:

Look at this very basic C++ code:

if(!glfwInit())
{
    return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
if (window==NULL)
{
    return -1;
}
glfwMakeContextCurrent(window);

std::cout << "GL_VERSION: " << glGetString(GL_VERSION) << std::endl;

我不明白如何检测"我可以在行中设置的最大opengl版本:

I do not understand how i can "detect" max opengl version i can set in the lines:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

此行不能放在glfwMakeContextCurrent之前:

glGetString(GL_VERSION)

所以我的问题是如何在程序开始时检测系统支持的opengl版本.

So my question is how can i detect the versions of opengl my system supports at the beginning of the program.

谢谢

推荐答案

请参见 GLFW guid-窗口创建提示,其中明确指出:

See GLFW guid - Window creation hints which clearly says:

GLFW_CONTEXT_VERSION_MAJORGLFW_CONTEXT_VERSION_MINOR指定创建的上下文必须与之兼容的客户端API版本.这些提示的确切行为取决于请求的客户端API.

OpenGL:GLFW_CONTEXT_VERSION_MAJORGLFW_CONTEXT_VERSION_MINOR并不是硬约束,但是如果所创建上下文的OpenGL版本小于所请求的上下文,则创建将失败.因此,将1.0版的默认值用于旧版代码是绝对安全的,并且如果可用,您仍将获得3.0版及更高版本的向后兼容上下文.

虽然无法向驱动程序询问受支持的最高版本的上下文,但是当您要求版本1.0的上下文时,GLFW会尝试提供该上下文,这是这些提示的默认设置. >

GLFW_CONTEXT_VERSION_MAJOR and GLFW_CONTEXT_VERSION_MINOR specify the client API version that the created context must be compatible with. The exact behavior of these hints depend on the requested client API.

OpenGL: GLFW_CONTEXT_VERSION_MAJOR and GLFW_CONTEXT_VERSION_MINOR are not hard constraints, but creation will fail if the OpenGL version of the created context is less than the one requested. It is therefore perfectly safe to use the default of version 1.0 for legacy code and you will still get backwards-compatible contexts of version 3.0 and above when available.

While there is no way to ask the driver for a context of the highest supported version, GLFW will attempt to provide this when you ask for a version 1.0 context, which is the default for these hints.


这意味着,如果您想获得尽可能高的OpenGL上下文,则可以完全跳过 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, ) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, ) .


This means, if you want to get the highest possible OpenGL context, then you can completely skip glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, ) and glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, ).

创建上下文后,可以使用 glGetString(GL_VERSION) .

After you have created a context, you can ask for the context version, with glGetString(GL_VERSION).

但是,如果您的应用程序要求最低的OpenGL版本,则需要通过以下方式告知GLFW:

But if your application requires a minimum OpenGL version, you need to tell that to GLFW, with:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, required_major);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, required_minor);

如果无法满足要求,则

glfwCreateWindow 将会失败

glfwCreateWindow will fail, if the requirements cannot be fulfilled.


您问题的答案


The answer to your question

我怎么知道我的系统支持哪个opengl版本?

How can i know which opengl version is supported by my system?

是:

您必须先创建一个OpenGL上下文,然后可以通过 glGetString(GL_VERSION) .

You have to create an OpenGL context first, then you can ask for the version by glGetString(GL_VERSION).


如评论中所述,当您尝试创建核心配置文件上下文时,此方法将失败.

As mentioned in the comment, this approach is going to fail when you try to create a core profile context.

这意味着您不能使用:

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

这篇关于我怎么知道我的系统支持哪个opengl版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆