作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我试图在 Android 上的 OpenGL ES 2.0+ 中绘制一个球体,但我在 Logcat 中看到以下错误:
glDrawElements is called with VERTEX_ARRAY client state disabled!
我查看了此调用的文档,但看不到我可能做错的任何事情。从错误来看,我似乎在某处遗漏了一些设置。
这是我正在执行设置的 VertexBuffer 类:
public class VertexBuffer {
private final int mBufferId;
public VertexBuffer(float[] vertexData) {
// Allocate a buffer
final int[] buffers = new int[1];
glGenBuffers(buffers.length, buffers, 0);
if (buffers[0] == 0) {
throw new RuntimeException("Could not create a new VBO");
}
mBufferId = buffers[0];
// Bind to the buffer
glBindBuffer(GL_ARRAY_BUFFER, mBufferId);
// Transfer data to native memory
FloatBuffer vertexArray = ByteBuffer
.allocateDirect(vertexData.length * BYTES_PER_FLOAT)
.order(ByteOrder.nativeOrder())
.asFloatBuffer()
.put(vertexData);
vertexArray.position(0);
// Transfer data from native memory to the GPU buffer
glBufferData(GL_ARRAY_BUFFER, vertexArray.capacity() * BYTES_PER_FLOAT, vertexArray, GL_STATIC_DRAW);
// IMPORTANT: Unbind from the buffer when we are done with it
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
public void setVertexAttribPointer(int dataOffset, int attributeLocation, int componentCount, int stride) {
glBindBuffer(GL_ARRAY_BUFFER, mBufferId);
glVertexAttribPointer(attributeLocation, componentCount, GL_FLOAT, false, stride, dataOffset);
glEnableVertexAttribArray(attributeLocation);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
最佳答案
添加:
setEGLContextClientVersion(2);
关于android - 在禁用 VERTEX_ARRAY 客户端状态的情况下调用 glDrawElements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33770569/
我试图在 Android 上的 OpenGL ES 2.0+ 中绘制一个球体,但我在 Logcat 中看到以下错误: glDrawElements is called with VERTEX_ARRA
我是一名优秀的程序员,十分优秀!