2

尝试设置以下一个或多个 OpenGL 标志:

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

使glfwOpenWindow失败。为什么会这样?

[编辑] 它似乎适用于 MAJOR=3 和 MINOR=2,但运行代码的笔记本电脑(MacBook Retina Mid2012)可以运行到 OpenGL 4.1(Intel HD 4000 有 OpenGL 4.0,Nvidia GT 650M 有 4.1) . [/编辑]

此外,虽然它可能不相关,但会glfwGetGLVersion返回0所有三个参数。

下面的完整示例代码:

int main(int argc, char * argv[])
{
    if(!glfwInit()) {
        return EXIT_FAILURE;
    }

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

    {
        int *major = new int, *minor = new int, *rev = new int;
        glfwGetGLVersion(major, minor, rev);
        std::cout << *major << " " << *minor << " " << *rev << std::endl;
        delete major;
        delete minor;
        delete rev;
    }

    if(!glfwOpenWindow(512,512,
                       8,8,8,
                       8,24,8,
                       GLFW_WINDOW)) {
        return EXIT_FAILURE;
            // APPLICATION EXITS HERE IF ONE OF THE FLAGS ARE SET.
    }

    while (glfwGetWindowParam(GLFW_OPENED)) {   
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers();
    }

    glfwTerminate();
    return 0;
}
4

1 回答 1

6

如果是 MacBook,您可能正在运行 OSX。虽然您的显卡能够支持 OpenGL 4.x,但OSX仅支持 OpenGL 3.2。

于 2013-06-03T19:26:35.047 回答