我一直在使用Xcode中的GLFW 2进行OpenGL项目,一切都运行得很好。我能够创建一个3.2 OpenGL上下文,并渲染所有内容。
然而,昨天我安装了GLFW3 lib并进行了修正建议。现在我根本无法创建3.2上下文,它总是返回3.0.3上下文。我能做错什么?
我在glfw之前加入了glew标题
这是我的初始化代码:
if(!glfwInit()){
std::cout << "ERROR IN glfwInit()" << std::endl;
return;
}
mWindow = glfwCreateWindow(mWidth, mHeight, "GLFW Renderer", NULL, NULL);;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if(!mWindow){
std::cout << "ERROR IN glfwOpenWindow" << std::endl;
glfwTerminate();
return;
}
/* Make the window's context current */
glfwMakeContextCurrent(mWindow);
int major, minor, rev;
glfwGetVersion(&major, &minor, &rev);
std::cout << "OpenGL " << major << "." << minor << "." << rev << std::endl;
glewExperimental = GL_TRUE;
if(glewInit() != GLEW_OK){
std::cout << "ERROR INITIALIZING GLEW" << std::endl;
return;
}
glViewport(0, 0, mWidth, mHeight);
编辑:将GLFW_CONTEXT_VERSION_MINOR更改为2
答案 0 :(得分:5)
正如Brett Hale建议的那样,我在创建窗口之前通过指定glfwWindowHints来解决它,这非常有意义。
答案 1 :(得分:-1)
当我把
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
我的窗口无法创建,我在声明窗口并创建它之前放了windowHints。
我只有:
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);