Reputation:
I have just started to learn about the OpenGL API using https://www.learnopengl.com/ and was using the code from the Hello Window tutorial to open a new GLFW window. However, something is not quite right as the console opens up immediately when executed but the window takes 2 seconds to open. Using the Visual Studio debugger I have found that glfwCreateWindow() seems to be the culprit but no information seems to exist on why it is slow for me.
The code goes as follows:
#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);
}
I am using Visual Studio 2017 and have already tried running in debug and release mode as well as using different GLFW libs but to avail.
Upvotes: 3
Views: 777
Reputation:
Nevermind, it turns out that I had set the preferred graphics processor in the NVIDIA Control Panel to be my GPU rather than auto-select which was causing the program to load in many OpenGL extensions using my GPU and therefore take longer to open the window. After changing the setting, the window opens in a much more reasonable time of 500 milliseconds by using the integrated graphics.
Upvotes: 2