OpenGL C++(制作简单窗口时抛出错误)



在c ++中创建基本的openGL窗口时,我收到一个错误。我在Visual Studio 19上使用GLFW和GLADE,我很确定我的计算机规格足够好。我想我正确地链接了我所有的 glfw 文件,并且所有带有 Glad 的内容都已正确附加。

The error: Exception thrown at 0x00000000 in OpenGL.exe: 0xC0000005: Access 
violation executing location 0x00000000.

我编写的完整代码(一些来自教程(。是的,包含很奇怪,但所有包含都正确添加,我确保。: `

#include <GLFW/glad.h>                                       
#include <GLFW/khrplatform.h>
#include <GLFW/glfw3.h>
int main()
{
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);
float vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f,  0.5f, 0.0f
};
unsigned int buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
/* 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;
}

>你必须初始化快乐:)

#include <glad/glad.h>
int main(int argc, char **argv) { 
// .. setup the context 
if(!gladLoadGL()) 
{ 
printf("Something went wrong!n");    
exit(-1); 
} 
printf("OpenGL %d.%dn",  GLVersion.major, GLVersion.minor);
// .. render here .. 
}

相关内容

最新更新