【发布时间】:2017-10-03 19:24:44
【问题描述】:
我正在运行 Mac OS X Sierra 10.12.6 (16G29)。我正在使用 macbook pro。
我已经安装了 brew 和以下软件包:
brew install glfw3
brew install glew
brew install glm
这是我的 c++ 程序:
#include <iostream>
#include <GLFW/glfw3.h>
GLFWwindow* window;
#include <GL/gl.h>
int main(int argc, const char * argv[])
{
if (!glfwInit())
{
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// Should be true for macOS, according to GLFW docs, to get core profile.
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// According to Apple docs, non-core profiles are limited to version 2.1.
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(640, 480, "Test 1", NULL, NULL);
if( window == NULL )
{
return -1;
}
glfwMakeContextCurrent(window);
// glGetString(GL_VERSION) is NULL at this point
return 0;
}
这是我正在运行的命令行来编译我的程序:
g++ program.cpp -I/opt/X11/include -L/opt/X11/lib -lglfw -lGL -lGLEW
存在运行时问题,因为我得到一个 NULL 窗口。 我在 Linux 虚拟机上编译了相同的代码,效果很好……
【问题讨论】:
-
您是否在构建设置中添加了“OpenGL.framework”?
-
我不使用可可应用程序或 Xcode。我在我的问题中输入的文件是一个文本文件
-
尝试用
-framework OpenGL替换(或添加,我不确定)-lGL并确保路径上有这个框架目录。(可能是/System/Library/Frameworks/OpenGL.framework) -
尝试使用
glfwSetErrorCallback打印 GLFW 给您的错误。当glfwCreateWindow返回NULL时,这意味着窗口创建失败并且是内部问题,可能与您的系统有关。
标签: c++ macos opengl glfw glew