【发布时间】:2015-07-03 17:05:30
【问题描述】:
我有一个 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 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 \
...也许我错过了一个选项。非常感谢您的帮助!
【问题讨论】:
-
FWIW
glew在 OS X 上只给我带来了问题。我删除了它,一切都很好。好吧,我必须导入<OpenGL/OpenGL.h>和<OpenGL/gl3.h>并且然后它起作用了。