无法使用GLFW设置GL标志

时间:2013-06-03 18:35:03

标签: c++ opengl glfw

尝试设置以下一个或多个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;
}

1 个答案:

答案 0 :(得分:6)

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