无法使用 OpenGL 3.3 上下文 macOS 创建窗口,并通过 brew 安装 GLFW

Ace*_*ami 2 c opengl haskell glfw

使用命令通过 brew 安装 glfw 后,我无法创建版本超过 2.1 的 GLFW 窗口brew install glfw

基本上我的问题是这段代码有效:

import qualified Graphics.UI.GLFW as GLFW

configAndCreateWindow :: IO (Maybe GLFW.Window)
configAndCreateWindow = do              
    GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 2)
    GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 1)
    GLFW.createWindow 100 100 "test" Nothing Nothing

main :: IO ()
main = do
    GLFW.init
    maybeWindow <- configAndCreateWindow
    case maybeWindow of
        Nothing -> putStrLn "Failure :("
        Just _ -> putStrLn "Success!"
Run Code Online (Sandbox Code Playgroud)

但如果我改变

GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 2)
GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 1)
Run Code Online (Sandbox Code Playgroud)

GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 3)
GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 3)
Run Code Online (Sandbox Code Playgroud)

它坏了。

为了确保它与 GLFW-b 无关,我还编写了 ac 程序:

#define GLFW_INCLUDE_GL_3
#include <GLFW/glfw3.h>
#include <stdio.h>

int main ()
{
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

    GLFWwindow* window = glfwCreateWindow(800, 600, "GLFW test", NULL, NULL);
    if (window == NULL) {
        printf("Success!");
    } else {
        printf("Failure :(");
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我更改上下文版本号,它就像 Haskell 示例一样工作。

BDL*_*BDL 5

在 MacOS 上请求 OpenGL 上下文时,必须设置两个额外的标志:

glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
Run Code Online (Sandbox Code Playgroud)