簡體   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