在使用命令brew install glfw
通过brew安装glfw之后,我无法创建2.1版以上的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!"
但是如果我改变
GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 2)
GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 1)
到
GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 3)
GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 3)
它坏了。
为了确保它与GLFW-b无关,我还编写了一个c程序:
#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 :(");
}
}
如果我更改上下文版本号,则其工作方式与Haskell示例相同。
答案 0 :(得分:2)
在MacOS上请求OpenGL上下文时,必须设置两个附加标志:
glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);