本文介绍了OpenGLException:禁用数组缓冲区对象时无法使用偏移量..在调用glEnable(GL_ARRAY_BUFFER)后的一行上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此异常:

Exception in thread "main" org.lwjgl.opengl.OpenGLException: Cannot use offsets when Array Buffer Object is disabled
at org.lwjgl.opengl.GLChecks.ensureArrayVBOenabled(GLChecks.java:93)
at org.lwjgl.opengl.GL11.glVertexPointer(GL11.java:2680)
at Joehot200.TerrainDemo.render(TerrainDemo.java:2074)
at Joehot200.TerrainDemo.enterGameLoop(TerrainDemo.java:3266)
at Joehot200.TerrainDemo.startGame(TerrainDemo.java:3490)
at StartScreenExperiments.Test2.resartTDemo(Test2.java:55)
at StartScreenExperiments.Test2.main(Test2.java:41)

但是,数组缓冲区对象已启用!

However, the array buffer object IS enabled!

glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glVertexPointer(3, GL_FLOAT, 0, 0L);

如您所见,在glVertexPointer调用之前两行(错误所在的那一行),那么我显然在启用数组缓冲区!

As you can see, two lines before the glVertexPointer call (the one that the error is at), then I am clearly enabling the array buffer!

这是怎么了?

推荐答案

顶点缓冲区不是您启用或禁用的对象-LWJGL会误导您.

您需要了解glVertexPointer命令使用绑定到GL_ARRAY_BUFFER(数组缓冲区对象")的任何内容作为其内存源(从OpenGL 1.5开始).

Vertex Buffers are not something you enable or disable - LWJGL is misleading you.

You need to undertand that the glVertexPointer command uses whatever is bound to GL_ARRAY_BUFFER ("Array Buffer Object") as its memory source (beginning with OpenGL 1.5).

在某些版本的OpenGL(1.5-3.0和3.1+兼容性)中,如果将 0 绑定到GL_ARRAY_BUFFER,则glVertexPointer的最后一个参数是实际的 pointer 到您的 程序的 内存(客户端内存),而不是到GPU内存(服务器内存)的 offset . Core OpenGL 3.1+甚至不支持客户端顶点存储,因此最后一个参数始终是偏移量.

In certain versions of OpenGL (1.5-3.0 and 3.1+ compatibility) if you have 0 bound to GL_ARRAY_BUFFER, then the last parameter to glVertexPointer is an actual pointer to your program's memory (client memory) rather than an offset into GPU memory (server memory). Core OpenGL 3.1+ does not even support client-side vertex storage, so that last parameter is always an offset.

该错误消息实际上表示您在调用glVertexPointer (...)时已将 0 绑定到GL_ARRAY_BUFFER.只要没有绑定到GL_ARRAY_BUFFER的任何地方,LWJGL显然都会考虑数组缓冲区对象 已禁用" .那不是不合理,但是它的确使您相信这是可以使用glEnableglDisable启用或禁用的状态.不是.

The error message really means that you have 0 bound to GL_ARRAY_BUFFER when you call glVertexPointer (...). LWJGL apparently considers Array Buffer Objects "disabled" whenever nothing is bound to GL_ARRAY_BUFFER. That is not too unreasonable, but it does lead you to believe that this is a state that can be enabled or disabled using glEnable or glDisable; it is not.

还记得当您绑定到GL_ARRAY_BUFFER时,我如何将glVertexPointer的最后一个参数描述为 offset ?由于LWJGL基于Java,因此无法将任意内存地址作为整数传递.传递给glVertexPointer (...) 的整数值必须是当前绑定的顶点缓冲区的内存中的偏移量.

Remember how I described the last parameter to glVertexPointer as an offset when you have something bound to GL_ARRAY_BUFFER? Since LWJGL is Java-based, there is no way to pass an arbitrary memory address as an integer. An integer value passed to glVertexPointer (...) must be an offset into the currently bound vertex buffer's memory.

void glVertexPointer(int size, int type, int stride, java.nio.ByteBuffer pointer);

服务器端顶点规范

void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset);

如您所见,LWJGL中有glVertexPointer函数的另一种形式,可以占用未存储在缓冲区对象中的内存,您在其中传递了java.nio.Buffer的特殊化.当没有顶点缓冲区绑定并且 是错误消息真正告诉您的时候,这就是您期望使用的形式.

As you can see, there is an alternate form of the glVertexPointer function in LWJGL that can take memory not stored in a buffer object, where you pass a specialization of java.nio.Buffer. That is the form you are expected to use when you have no vertex buffer bound and that is what the error message is really telling you.

由于某些原因,vboVertexHandle似乎是 0 或某些未在应用程序中使用glGenBuffers (...)生成的值.在初始化VBO的地方显示代码将是helfpul.

For some reason vboVertexHandle appears to be 0 or some value not generated using glGenBuffers (...) in your application. Showing the code where you initialize the VBO would be helfpul.

这篇关于OpenGLException:禁用数组缓冲区对象时无法使用偏移量..在调用glEnable(GL_ARRAY_BUFFER)后的一行上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:42