Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

c++ - Process finished with exit code -1073741515 when calling GLEW functions

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?

question from:https://stackoverflow.com/questions/65897845/process-finished-with-exit-code-1073741515-when-calling-glew-functions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...