Search code examples
openglopengl-3

GLGenVertexArrays giving me an invalid memory address


I am new to openGL and I have search around the web and followed some tutorials but I am still having an issue. When I run my project I get a error:

Unhandled exception at 0x0000000000000. Access Violation executing location 0x0000000000000

Below is my code that I am executing that is causing this exception and would love some help on nailing down my issue:

GLuint vertextBuffer;
GLuint vertexArrayID;
glGenVertexArrays(1, &vertexArrayID);
glBindVertexArray(vertexArrayID);
glGenBuffers(1, &vertextBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertextBuffer);

The exception occurs when I try to bind both the VBO and VAO.

Thanks for the help in advance!


Solution

  • All functions and extensions of OpenGL > 1.1 have to be loaded in order to be used. This can be done, for example, by using glew which has to be initialized as follows:

    glewExperimental = true;
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
        ...
    }
    

    (Example code is from http://glew.sourceforge.net/)