gpt4 book ai didi

opengl - 我如何知道我的系统支持哪个opengl版本

转载 作者:行者123 更新时间:2023-12-03 01:59:41 25 4
gpt4 key购买 nike

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

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 版本:

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

此行不能放在 glfwMakeContextCurrent 之前:

glGetString(GL_VERSION)

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

谢谢

最佳答案

参见GLFW guid - Window creation hints其中清楚地表明:

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, ) .

创建上下文后,您可以询问上下文版本, glGetString(GL_VERSION) .

但是,如果您的应用程序需要最低 OpenGL 版本,则需要将其告知 GLFW,方法是:

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

glfwCreateWindow如果不能满足要求,就会失败。


回答你的问题

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

是:

您必须先创建OpenGL上下文,然后您可以通过glGetString(GL_VERSION)询问版本.


更正答案

正如评论中提到的,当您尝试创建核心配置文件上下文时,此方法将失败

这意味着您不能使用:

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

关于opengl - 我如何知道我的系统支持哪个opengl版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46510889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com