按照本教程开始学习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;
}
}
Run Code Online (Sandbox Code Playgroud)
这总是产生"无法打开GLFW窗口"错误.我下载了源代码,看看是否会编译并将差异缩小到GLFW_OPENGL_VERSION_MINOR变量.
如果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;
}
Run Code Online (Sandbox Code Playgroud)
如果这是原因(它看起来像是这样)究竟是什么意思,为什么它会阻止窗口被创建?