使用VBO出现访问冲突 [英] Access violation using VBO with glew

查看:76
本文介绍了使用VBO出现访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OpenGL项目中使用VBO.我正在使用glew库进行扩展,并使用glfw进行Windows处理.当我尝试创建VBO应用程序时崩溃,我得到

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

在symulator3C.exe中0x00000000处未处理的异常:0xC0000005: 访问冲突

Unhandled exception at 0x00000000 in symulator3C.exe: 0xC0000005: Access violation

在函数glGenBuffersARB中的

.这是我的代码:

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

}

我不知道怎么了.当然,在调用此函数之前,我先调用glewInit(),结果是成功. 我正在使用Visual Studio 2010

I don't know what's wrong. Of course before calling this function I call glewInit() and result is success. I'm using Visual Studio 2010

推荐答案

由于您的程序在首次使用VBO相关功能时失败,因此听起来您要么未正确初始化GLEW(一旦GL上下文已创建并处于活动状态),或者您的硬件不支持VBO.

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.

只需检查您的硬件是否支持GL_ARB_vertex_buffer_object或OpenGL版本是否至少为1.5,在这种情况下,您可以使用VBO函数的核心版本(不带ARB后缀,但是您仍然需要正确初始化的GLEW,当然):

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

并确保您使用的是最新的图形驱动程序.如果使用Windows默认驱动程序,则该驱动程序可能仅支持OpenGL 1.1.

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.

这篇关于使用VBO出现访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆