繁体   English   中英

运行使用 OpenGL 3.3 的 mac os x c++ 程序

[英]Running mac os x c++ program working with OpenGL 3.3

我正在运行 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 虚拟机上编译了相同的代码,效果很好......

这在 GLFW 文档中得到了回答: http ://www.glfw.org/docs/latest/window_guide.html

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);

另请参阅: https : //developer.apple.com/opengl/OpenGL-Capabilities-Tables.pdf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM