运行Mac OS X C 程序与OpenGL 3.3一起工作

Running mac os x c++ program working with OpenGL 3.3

本文关键字:OpenGL 一起 工作 程序 Mac OS 运行      更新时间:2023-10-16

我正在运行Mac OS X Sierra 10.12.6(16G29)。我正在研究MacBook Pro。

我已经安装了啤酒和以下软件包:

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

有一个运行时问题,因为我得到了一个空窗口。我已经在Linux虚拟机上编译了相同的代码,并且效果很好...

glfw docs: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