运行与OpenGL 3.3配合使用的Mac OS X C ++程序 [英] Running mac os x c++ program working with OpenGL 3.3

查看:115
本文介绍了运行与OpenGL 3.3配合使用的Mac OS X C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Mac OS X Sierra 10.12.6(16G29).我正在开发Macbook Pro.

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

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

I have installed brew and the following packages:

brew install glfw3
brew install glew
brew install glm

这是我的c ++程序:

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

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

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...

推荐答案

在GLFW文档中对此进行了回答: http://www.glfw.org/docs/latest/window_guide.html

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

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

这篇关于运行与OpenGL 3.3配合使用的Mac OS X C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆