I've written a basic OpenGL program in C++ which just opens a window. I'm now trying to draw a triangle, but I'm having some issues calling GLEW functions. This is my code with just OpenGL:
#include "include/glew.h"
#include "include/glfw3.h"
int main()
{
GLFWwindow* window;
if (!glfwInit())
return -1;
window = glfwCreateWindow(800, 600, "HelloWorld", nullptr, nullptr);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
unsigned int buffer;
//glGenBuffers(1, &buffer);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Uncommenting glGenBuffers(1, &buffer);
, which is a GLEW function, causes the program to exit with code -1073741515
. No errors were displayed. I've correctly linked with GLEW, as well as opengl32, gdi32, user32, and shell32. What am I doing wrong?
You have to Initialize GLEW. Call glewInit
right after making the OpenGL context current:
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK)
return 0;
In addition, you have to make sure that the DLL files can be found at runtime. Add a path to the Windows path environment variable or place the DLL files in the same directory as the executable.