我有一台2014年的RMBP,升级到最新版本的OS X应该保证我兼容OpenGL 4.1。我已经组建了一个最小工作示例:
#include <iostream>
#include "GL/glew.h"
#include <GLFW/glfw3.h>
using namespace std;
int main(){
int windowWidth = 800;
int windowHeight = 800;
string windowTitle = "title";
glfwDefaultWindowHints();
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
if( !glfwInit() )
{
cerr << "Failed to initialize GLFW.\n";
return 1;
} else {
clog << "Initialized GLFW." << endl;
}
GLFWwindow* pWindow = glfwCreateWindow(windowWidth, windowHeight, windowTitle.c_str(), 0, NULL);
glfwSetWindowPos(pWindow, 700, 200);
glfwMakeContextCurrent(pWindow);
if( pWindow == NULL )
{
cerr << "Failed to open GLFW window.\n";
glfwTerminate();
return 1;
}
std::cout << "GL Version: " << glGetString(GL_VERSION) << "\n";
std::cout << "GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
while (!glfwWindowShouldClose(pWindow))
{
glfwPollEvents();
}
glfwDestroyWindow(pWindow);
return 0;
}
这将打开一个窗口,它可以正常工作,但输出如下: GL 版本:2.1 INTEL-10.0.86 GLSL 版本:1.20 供应商:Intel Inc. 渲染器:Intel Iris OpenGL 引擎
这是错误的!我应该得到4.1兼容性。我下载了https://github.com/tomdalling/opengl-series上的示例,在xCode下,它确实升级到了4.1,所以我知道我的电脑是有能力的。
这实际上是为了一个更大的项目;我尝试将我的项目导入xcode中,并与Tom Dalling的项目合并,但它就是不起作用,我总是得到GL 2.1。
我正在使用以上代码进行编译。
g++ main.cpp -o GLTEST -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \
也许我错过了某个选项。非常感谢您的帮助!
glew
只会带来问题。我把它删除后一切都好了。然后,我不得不导入<OpenGL/OpenGL.h>
和<OpenGL/gl3.h>
,这样才能正常工作。 - Bjorn