【发布时间】:2020-10-12 13:57:23
【问题描述】:
我正在使用 GLFW + GLAD 或 GLEW (#include glad/glad.h#include <GL/glew.h>) 设置 opengl。
在函数 glfwMakeContextCurrent(window); 之后,我需要检查 GLAD 或 GLEW 是否已正确初始化,否则我将在 Visual Studio 2019 中遇到异常错误。
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
int main(void) {
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Check if GLEW is ok after valid context */
/*if (glewInit() != GLEW_OK) {
cout << "Failed to initialize GLEW" << endl;
}*/
/* or Check if GLAD is ok after valid context */
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
cout << "Failed to initialize GLAD" << endl;
return -1;
}
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
...
}
glfwTerminate();
return 0;
}
我在这里使用 GLAD。我真的不明白为什么我必须检查这个。提前致谢。
【问题讨论】:
标签: c++ visual-studio opengl glew