GLFW Fails to Open Window in OSX
Asked Answered
B

1

9

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.

Bontebok answered 5/4, 2014 at 22:53 Comment(4)
Are you getting any error messages?Grith
The only error message that I'm getting is when is checks the window to be null and prints a message and returns. If I do switch the context to 2.1 or remove setting the context, I get an incompatibility error message when trying to load the shaders.Bontebok
This answer might help: #22214374Grith
Thank you! Realized I wasn't setting an error callback which I did, then leading me to the answer.Bontebok
B
17

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.

Bontebok answered 6/4, 2014 at 1:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.