Creating OpenGL 3.3 Context with GLFW in Mac OS X 10.9
Asked Answered
A

1

2

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

And, indeed, GLFW won't give me a OpenGL 3+ context without setting the forward-compatibility flag (in Mac OS X).

Why is that? Is there any way to get a OpenGL 3+ context in Mac OS X 10.9 without forward-compatibility? Is it a limitation of OpenGL implementation for OS X or a problem of GLFW?

Abduce answered 6/3, 2014 at 2:48 Comment(0)
G
6

This is actually the correct behavior, as defined in the OpenGL Programming Guide for Mac.

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. This implies that you will not be able to use any deprecated functions when programming against OpenGL 3.x/4.x on a Mac.

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.

Greatcoat answered 6/3, 2014 at 15:3 Comment(1)
That request would be denied. The returned context is always forward-compatible and core profile, because that is what OS X supports. GLFW will not break those hard constraints. Doing so would undermine application portability.Bethanybethe

© 2022 - 2024 — McMap. All rights reserved.