使用glGenVertexArrays时发生GLEW OpenGL访问冲突

时间:2013-12-24 21:21:21

标签: opengl sdl glew

在我的情况下..通过更新显卡驱动程序解决了这个问题。


我在stackoverflow和互联网上搜索并发现了同样问题的人。但是,答案并没有解决我的问题。

我正在使用SDL2和GLEW。当我运行应用程序时,执行此函数时收到“访问冲突”错误:

glGenVertexArrays(1, &VertexArrayID); 

我的代码:

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;
}

1 个答案:

答案 0 :(得分:7)

尝试在glewInit()之前添加这个,glewExperimental = GL_TRUE;。

glewExperimental = GL_TRUE;
glewInit();