我正在尝试在Lion上设置OpenGL 3.2上下文。我有以下代码来设置窗口:

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

if (!glfwInit())
    return -1;

if (!glfwOpenWindow(640, 480, 8, 8, 8, 0, 0, 0, GLFW_WINDOW))
    return -1;

glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

// Get OpenGL details
int major, minor, rev;
glfwGetGLVersion(&major, &minor, &rev);
std::cout << "GL Version: " << major << "." << minor << "." << rev << std::endl;

即使我运行的是OS X Lion和显然支持3.2的AMD Radeon 6750M,GL版本仍为2.1。另外,我运行了这段C代码here,它返回了3.2。我正在使用GLFW 2.7.8。有人知道这是怎么回事吗?

最佳答案

事实证明,我需要在调用glfwInit()之前先调用glfwOpenWindowHint:

if (!glfwInit())
    return -1;

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

if (!glfwOpenWindow(500, 500, 8, 8, 8, 0, 0, 0, GLFW_WINDOW))
    return -1;

09-25 21:31