SDL + OpenGL: access violation when creating buffer

I'm trying to make a window using SDL and then draw to it using GLEW and OpenGL.

so far I've made a window and initialized it with OpenGL, but when I try to create a buffer I get a wired exception.

My code looks like this:

#include <GLglew.h>
#include <SDL.h>
#include <iostream>

int main(int argc, char** argv)
{

    SDL_Window* window;
    SDL_Init(SDL_INIT_EVERYTHING);

    //creating SDL window
    window = SDL_CreateWindow("",100,100,500,400,SDL_WINDOW_OPENGL);

    //setting up opengl
    SDL_GL_CreateContext(window);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    glClearColor(0.6f, 0.0f, 0.0f, 1.0f);

    //check if glew was initialized properly
    if (glewInit() == GLEW_OK)
        std::cout << "glew ok" << std::endl;
    else
        goto end;

    ////////////////////////////////////////////////I'm Getting The Error Here
    GLuint bufferID;////////////////////////////////
    glCreateBuffers(1,&bufferID);///////////////////
    glDeleteBuffers(1,&bufferID);///////////////////

    SDL_Event sdlEvent;

    //event loop
    while (1)
        while (SDL_PollEvent(&sdlEvent))
            if (sdlEvent.type == SDL_QUIT)
                goto end;

    end:
        SDL_Quit();

    return 0;
}

error: Exception thrown at 0x00000000 in opengl_project.exe: 0xC0000005: Access violation executing location 0x00000000.


the problem was that opengl was outdated (version 4.3) and glCreateBuffers is a 4.5+ feature

If you have a simular problem a solution could be updating your graphics driver or just using glGenBuffers (version 1.5+) instead.

链接地址: http://www.djcxy.com/p/38464.html

上一篇: CUDA中的块尺寸

下一篇: 创建缓冲区时SDL + OpenGL:访问冲突