问题
I'm trying to use VBO in my OpenGL project. I'm using glew library for extensions and glfw for windows handling. When I try to create VBO application crashes and I get
Unhandled exception at 0x00000000 in symulator3C.exe: 0xC0000005: Access violation
in function glGenBuffersARB. Here's my code:
GLuint vboId1=0; //this is global variable
void createVBO(){
normalsVBO = (float *) malloc(sizeof(float)*3*(SIZE_X-1)*SIZE_Y*2);
verticesVBO = (float *) malloc(sizeof(float)*3*(SIZE_X-1)*SIZE_Y*2);
if(normalsVBO==NULL) exit(-1);
if(verticesVBO==NULL) exit(-1);
glGenBuffersARB(1, &vboId1); //HERE IT CRASHES!
// bind VBO in order to use
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId1);
...
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(float)*3*(SIZE_X-1)*SIZE_Y*2, verticesVBO, GL_DYNAMIC_DRAW);
glEnableClientState(GL_VERTEX_ARRAY); // activate vertex coords array
glVertexPointer(3, GL_FLOAT, 0, 0);
}
I don't know what's wrong. Of course before calling this function I call glewInit() and result is success. EDIT: I'm using Visual Studio 2010
回答1:
Since your program fails at the first use of a VBO related function, it sounds like you either didn't initialize GLEW properly (by calling glewInit
once the GL context is created and active) or your hardware just doesn't support VBOs.
Just check if your hardware supports GL_ARB_vertex_buffer_object or if the OpenGL version is at least 1.5, in which case you can use the core versions of the VBO functions (without the ARB suffix, but you still need a properly initialized GLEW for these, of course):
printf("%s\n", glGetString(GL_VERSION));
if(!strstr(glGetString(GL_EXTENSIONS), "GL_ARB_vertex_buffer_object"))
//no VBO extension
And make sure you work with a recent graphics driver. If you work with the Windows default driver, it may only support OpenGL 1.1.
来源:https://stackoverflow.com/questions/7862041/access-violation-using-vbo-with-glew