GLAD初始化

在GLAD初始化时,会用到下面的语句:

1
2
3
4
5
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}

并且在我的代码中,如果这段初始化代码的位置放置有问题,run的时候就直接输出Fail to initialize GLAD

如果按照下面的顺序放置,就会fail

1
2
3
4
5
6
7

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

其中,glfwMakeContextCurrent(window)函数是为了添加上下文。

想要正确的运行,要先添加上下文,再初始化GLAD。

原因未知,正在学习中。