简体   繁体   English

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

[英]Creating OpenGL 3.3 Context with GLFW in Mac OS X 10.9

I have the following code: 我有以下代码:

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

...

}

The problem is that I'm receiving the following message: https://github.com/glfw/glfw/blob/master/src/nsgl_context.m#L101 问题是我收到以下消息: https : //github.com/glfw/glfw/blob/master/src/nsgl_context.m#L101

And, indeed, GLFW won't give me a OpenGL 3+ context without setting the forward-compatibility flag (in Mac OS X). 而且的确,如果不设置前向兼容标记(在Mac OS X中),GLFW不会给我OpenGL 3+上下文。

Why is that? 这是为什么? Is there any way to get a OpenGL 3+ context in Mac OS X 10.9 without forward-compatibility? 有没有办法在Mac OS X 10.9中获得OpenGL 3+上下文而没有前向兼容性? Is it a limitation of OpenGL implementation for OS X or a problem of GLFW? 它是OS X的OpenGL实现的限制还是GLFW的问题?

This is actually the correct behavior, as defined in the OpenGL Programming Guide for Mac . 实际上,这是正确的行为,如MacOpenGL编程指南中所定义。

Mac OS X simply does not support the compatibility profile for OpenGL 3.x/4.x, so you must request a core (or forward-compatible) context. Mac OS X根本不支持OpenGL 3.x / 4.x的兼容性配置文件,因此您必须请求一个核心(或前向兼容)上下文。 This implies that you will not be able to use any deprecated functions when programming against OpenGL 3.x/4.x on a Mac. 这意味着在Mac上针对OpenGL 3.x / 4.x编程时,您将无法使用任何过时的功能。

It might be worth to make a feature request in the GLFW issue tracker to set the core profile flag implicitly when requesting a 3.x/4.x context on Mac OS X. 在Mac OS X上请求3.x / 4.x上下文时,可能值得在GLFW问题跟踪器中进行功能请求以隐式设置核心配置文件标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM