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

大城市里の小女人 提交于 2019-12-31 03:55:11

问题


I am running Mac OS X Sierra 10.12.6 (16G29). I am working on a macbook pro.

I have installed brew and the following packages:

brew install glfw3
brew install glew
brew install glm

Here is my c++ program:

#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;
}

And here is the command line i am running to compile my program:

g++ program.cpp -I/opt/X11/include -L/opt/X11/lib -lglfw -lGL -lGLEW

There is a runtime problem because i get a NULL window. I have compiled the same code on a Linux virtual machine and it works great...


回答1:


This is answered in the 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);

Also see: https://developer.apple.com/opengl/OpenGL-Capabilities-Tables.pdf



来源:https://stackoverflow.com/questions/46551933/running-mac-os-x-c-program-working-with-opengl-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!