OpenGL,GLFW,高兴。 glViewport(0, 0, 800, 600) 抛出内存错误

OpenGL, GLFW, GLAD. glViewport(0, 0, 800, 600) throwing memory errors

我最近开始关注 these OpenGL 教程。在 Hello Window 教程之前,我一直没有遇到任何问题,其中函数 gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) returns 为 false。这导致错误:

Exception thrown at 0x00000000 in openGL_001.exe: 0xC0000005: Access violation executing location 0x00000000.

Unhandled exception at 0x7281C1ED in openGL_001.exe: 0xC0000005: Access violation executing location 0x00000000.

在函数 glViewport(0, 0, 800, 600) 被调用时被抛出(见下面的代码)。我知道 GLAD 文件是问题所在,因为代码包含一个 if 语句(见下面的代码),检查 GLAD 是否已成功处理OpenGL 的函数指针。我尝试使用以下 GLAD configurations:

让它工作

语言:C/C++,规范:OpenGl

代码:

#include <iostream>
#include <glad\glad.h>
#include <GLFW\glfw3.h>

void framebuffer_size_callback(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, "Learn OpenGL", NULL, NULL);
if (window = NULL) {
    std::cout << "Failed to create GLFW window" << std::endl;
    glfwTerminate();
    return -1;
}
glfwMakeContextCurrent(window);

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

glViewport(0, 0, 800, 600);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

//render loop
while (!glfwWindowShouldClose(window)) {
    glfwSwapBuffers(window);
    glfwPollEvents();
}
glfwTerminate();
return 0;

}

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

}

相关(希望)系统信息:

在此先感谢您的帮助。如果您需要更多信息,请开火。 (请注意,此问题发布后的前 2 小时内我将无法回复。)

已解决。 if 语句中的拼写错误。缺少两个 =.

之一