我环顾四周,显然我可以在这个解决方案之间进行选择,而我的问题与以下相同: 文字, 但我仍然不知道如何解决这个问题。 当我使用 glClear(GL_COLOR_BUFFER_BIT); 时在xcode中,它会报警
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
,但是当我用“//”注释它时,该项目将工作。我尝试“//”这段代码,但它不会清除窗口的渲染。
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
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);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
在设置活动上下文后,您需要初始化 GL 入口点(函数指针),如下所示:
if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
// failed to load...
此外,如果使用 GLAD 库,请防止包含系统 GL 标头:
#include <glad/glad.h>
...
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
...