glfwWindowHint()调用后,GLFW窗口创建失败

时间:2014-09-18 03:46:08

标签: c++ opengl glfw

我正在尝试使用GLFW3创建一个窗口。当我在桌面上执行此操作时,它可以正常工作。在我的笔记本电脑上,它无法创建窗口,程序崩溃。删除glfwWindowHint()调用可防止崩溃,但我的代码不起作用,因为我得到了错误的openGL版本。这是窗口代码:

Window::Window(int width, int height, std::string title, bool full)
{
    glfwInit();
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    m_width = width;
    m_height = height;
    if (full)
    {
        m_window = glfwCreateWindow(width, height, title.c_str(), glfwGetPrimaryMonitor(), nullptr);
    }
    else
    {
        m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
    }
    glfwMakeContextCurrent(m_window);

    glewExperimental = GL_TRUE;
    glewInit();
    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, width, height);

}

这可能与我的桌面有NVidia显卡而我的笔记本电脑集成显卡的事实有关吗?

更新: 它在调用glfwSwapBuffers()时崩溃了,我将glfw错误65543打印到控制台。 glfwCreateWindow()返回NULL;

1 个答案:

答案 0 :(得分:0)

如果它向控制台输出错误65543,则相当于0x00010007,它在glfw3.h中定义为GLFW_VERSION_UNAVAILABLE。

/*! @brief The requested OpenGL or OpenGL ES version is not available.
 *
 *  The requested OpenGL or OpenGL ES version (including any requested context
 *  or framebuffer hints) is not available on this machine.
 *
 *  @par Analysis
 *  The machine does not support your requirements.  If your application is
 *  sufficiently flexible, downgrade your requirements and try again.
 *  Otherwise, inform the user that their machine does not match your
 *  requirements.
 *
 *  @par
 *  Future invalid OpenGL and OpenGL ES versions, for example OpenGL 4.8 if 5.0
 *  comes out before the 4.x series gets that far, also fail with this error and
 *  not @ref GLFW_INVALID_VALUE, because GLFW cannot know what future versions
 *  will exist.
 */
#define GLFW_VERSION_UNAVAILABLE    0x00010007