#OpenGL使用glViewport函数时 出现异常。
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
try
{
glViewport(0, 0, 80, 60);
}
catch ( std::exception& e)
{
std::cerr << e.what() << std::endl;
return -1;
}
glfwMakeContextCurrent(window);
getchar();
return 0;
}
#异常信息
在glViewport(0, 0, 80, 60);发出异常;
0x00000000 处(位于 LearnOpenGL.exe 中)引发的异常: 0xC0000005: 执行位置 0x00000000 时发生访问冲突。