Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLFW Fails to Open Window in OSX

Tags:

c++

opengl

glfw

I have the following code:

glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open window and create OpenGL context
GLFWwindow * window;
window = glfwCreateWindow(1024, 768, "OpenGL Testing", NULL, NULL);
if(window == NULL)
{
    fprintf(stderr, "Failed to open GLFW Window.\n");
    glfwTerminate();
    return -1;
}

It works fine on my desktop on both Ubuntu and Windows, but it fails on my laptop running OSX. I thought it was an issue with the laptop not supporting this version of OpenGL, but it supports up to 4.1 with the video card.

I have thought that it may be using the integrated intel GPU instead of the nVidia one, but as I understand from what I have seen, GLFW will force the correct GPU to do the rendering.

If I change the context to 2.1, everything seems to work, but then the shaders aren't compatible.

Any ideas?

UPDATE: If all of the glfwWindowHint() calls are removed, the window is created, but the shaders are incompatible. I assume if these are removed, GLFW automatically chooses a context, which happens to be incompatible with shaders with version 330 core.

like image 708
Daniel Underwood Avatar asked Apr 05 '14 22:04

Daniel Underwood


1 Answers

The problem came down to setting a forward compatibility flag in GLFW. This answer led to the answer of making the following call:

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

This is also shown in the GLFW FAQ.

like image 188
Daniel Underwood Avatar answered Oct 10 '22 04:10

Daniel Underwood