While creating a basic openGL window in c++ I get an error. I'm using GLFW and GLAD on Visual Studio 19, and i'm pretty sure my computer specs are good enough. I think I linked all my glfw files correctly and everything with Glad is properly attached.
The error: Exception thrown at 0x00000000 in OpenGL.exe: 0xC0000005: Access violation executing location 0x00000000.
The full code I've written (some from tutorial). And yes, the includes are weird, but all includes are added correctly, I made sure. : `
#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;
}
U have to init glad :)
#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.%d\n", GLVersion.major, GLVersion.minor);
// .. render here ..
}
User contributions licensed under CC BY-SA 3.0