gpt4 book ai didi

opengl - 关于低于 GL 3.2 的 GLFW 行为的问题

转载 作者:行者123 更新时间:2023-12-03 12:39:22 27 4
gpt4 key购买 nike

关注 this tutorial开始学习opengl我有以下源码:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>

using namespace glm;

int
main(void){
if(!glfwInit())
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}

glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.1
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

// Open a window and create its OpenGL context
if(!glfwOpenWindow(1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW))
{
int a = glfwOpenWindow(1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW);
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
return 1;
}

}

这总是会产生“无法打开 GLFW 窗口”错误。我下载了源代码以查看是否可以编译并将差异缩小到 GLFW_OPENGL_VERSION_MINOR 变量。

如果将次要设置为 2 或 3,则程序可以编译并运行良好,但如果设置为 1,则不会。这是 GLFW 中的错误还是这里发生了什么有趣的事情?

glfw 源码中 window.c 的第 487 行说:

if( wndconfig.glProfile &&
( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
{
// Context profiles are only defined for OpenGL version 3.2 and above
return GL_FALSE;
}

如果这是原因(看起来确实如此),这究竟意味着什么?为什么它会阻止创建窗口?

最佳答案

请阅读源中的评论消息。它说:

Context profiles are only defined for OpenGL version 3.2 and above

core profile 的概念在 OpenGL 3.1 中不存在。因此,当您要求 3.1 版时,您不能这样做:

glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

你要求的东西根本不存在,所以 GLFW 不允许你这样做。

如果您想要核心配置文件,请要求 GL 3.2 或更高版本。如果您要求较低的 GL 版本,请停止要求核心配置文件。

关于opengl - 关于低于 GL 3.2 的 GLFW 行为的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10862546/

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