我最近开始关注these OpenGL教程。在 Hello Window 教程中,函数gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)
返回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个小时内,我将无法回复。)
答案 0 :(得分:0)
解决。在if
陈述中的错字。缺少两个中的一个=
。