我在学习OpenGL的时候遇到的问题
目前还只是入门水平什么都不懂
先放个代码
#include<GL/glew.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;
}
cout << sizeof(float) << endl;
/* Make the window's context current */
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK) cout << "NotOK" << endl;
else cout << "OK" << endl;
cout << glGetString(GL_VERSION) << endl;
/* Loop until the user closes the window */
float data[6]
{
0.5f ,-0.5f,
-0.5f,-0.5f,
0 , 0.5f
};
unsigned int buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float),data,GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
是一个简单的绘制三角形的代码
从头到尾完全是参考视频教程中做的
能够顺利编译生成
运行时能够正确生成窗口和输出
但是很快程序就会被中断生成这个报错
最后附上我参考的视频教程链接
https://www.bilibili.com/video/BV1MJ411u7Bc?spm_id_from=333.1007.top_right_bar_window_custom_collection.content.click