user3125591
user3125591

Reputation: 123

GLEW OpenGL Access violation when using glGenVertexArrays

In my case.. This problem was fixed by updating the driver of the graphics card.


I have searched and found people with the same problem on stackoverflow and the internet. However, the answers aren't solving my problem.

I am using SDL2 and GLEW. When I run the application, I receive an ''Access violation'' error when this function is executed:

glGenVertexArrays(1, &VertexArrayID); 

My code:

bool Game::initSDL(char* title, int xpos, int ypos, int width, int height, int flags) {
if(SDL_Init(SDL_INIT_EVERYTHING)>=0) {
    Uint32 flags = SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL;
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,4);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    mainWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
    mainGLContext = SDL_GL_CreateContext(mainWindow);

    SDL_GL_SetSwapInterval(1);

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

    }
    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

    GLuint VertexArrayID;
    glGenVertexArrays(1, &VertexArrayID); 
    glBindVertexArray(VertexArrayID);

} else {
    return false;
}
return true;
}

Upvotes: 1

Views: 4019

Answers (1)

Jesse Laning
Jesse Laning

Reputation: 490

try adding this, glewExperimental = GL_TRUE;, before glewInit().

glewExperimental = GL_TRUE;
glewInit();

Upvotes: 6

Related Questions