GLFW - Window 需要 2 秒才能打开

GLFW - Window takes 2 seconds to open

我刚刚开始使用 https://www.learnopengl.com/ 了解 OpenGL API,并使用 Hello Window 教程中的代码打开一个新的 GLFW window。但是,有些事情不太对劲,因为控制台在执行时会立即打开,但 window 需要 2 秒才能打开。使用 Visual Studio 调试器,我发现 glfwCreateWindow() 似乎是罪魁祸首,但似乎没有关于为什么它对我来说很慢的信息。

代码如下:

#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <iostream>

void processInput(GLFWwindow* window);
void framebufferSizeCallback(GLFWwindow* window, int width, int height);

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL Test", nullptr, nullptr); //This line takes 2 seconds to execute
    if (window == nullptr)
    {
        std::cout << "Failed to instantiate GLFW window!" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        std::cout << "Failed to initialise GLAD" << std::endl;
        return -1;
    }

    while (!glfwWindowShouldClose(window))
    {
        processInput(window);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();

    return 0;
}

void processInput(GLFWwindow* window)
{
    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
    {
        glfwSetWindowShouldClose(window, true);
    }
}

void framebufferSizeCallback(GLFWwindow* window, int width, int height)
{
    glViewport(0, 0, width, height);
}

我正在使用 Visual Studio 2017 并且已经在调试和发布模式下尝试 运行 以及使用不同的 GLFW 库但是有用。

没关系,事实证明我在 NVIDIA 控制面板中将首选图形处理器设置为我的 GPU 而不是自动 select 这导致程序使用我的 GPU 在许多 OpenGL 扩展中加载因此需要更长的时间才能打开 window。更改设置后,window 使用集成显卡在 500 毫秒的更合理时间内打开。