我正试图在Android上用OpenGL ES 2.0+绘制一个球体,我在Logcat中看到以下错误:
在禁用VERTEX_ARRAY客户端状态的情况下调用glDrawElements!
我查看了这个电话的文档,我看不出任何可能出错的内容。从错误中听起来我错过了某些设置。
这是我正在进行设置的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);
}
}
答案 0 :(得分:8)
添加:
setEGLContextClientVersion(2);