在 Mac OS X 10.9 中使用 GLFW 创建 OpenGL 3.3 上下文

raf*_*ame 2 c++ opengl macos opengl-es glfw

我有以下代码:

void error_callback(int error, const char* description)
{
    fputs(description, stderr);
}

int main( void )
{

// Initialise GLFW
if( !glfwInit() )
{
    fprintf( stderr, "Failed to initialize GLFW\n" );
    return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
glfwSetErrorCallback(error_callback);
window = glfwCreateWindow( 1024, 768, "Tutorial 16 - Shadows", NULL, NULL);
if( window == NULL ){

    //fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
    glfwTerminate();
    return -1;
}
glfwMakeContextCurrent(window);

// Initialize GLEW
GLenum err;
glewExperimental = GL_TRUE; // Needed for core profile
if ((err = glewInit()) != GLEW_OK) {
    std::cout << glewGetErrorString(err) << std::endl;
    return -1;
}

...

}
Run Code Online (Sandbox Code Playgroud)

问题是我收到以下消息:https://github.com/glfw/glfw/blob/master/src/nsgl_context.m#L101

事实上,如果不设置前向兼容性标志(在 Mac OS X 中),GLFW 不会为我提供 OpenGL 3+ 上下文。

这是为什么?有没有办法在 Mac OS X 10.9 中获得 OpenGL 3+ 上下文而不向前兼容?这是 OS X OpenGL 实现的限制还是 GLFW 的问题?

The*_*ler 6

这实际上是正确的行为,如OpenGL 编程指南 for Mac中所定义。

Mac OS X 根本不支持 OpenGL 3.x/4.x 的兼容性配置文件,因此您必须请求核心(或向前兼容)上下文。这意味着在 Mac 上针对 OpenGL 3.x/4.x 进行编程时,您将无法使用任何已弃用的函数。

在 Mac OS X 上请求 3.x/4.x 上下文时,可能值得在GLFW 问题跟踪器中提出功能请求,以隐式设置核心配置文件标志。