gpt4 book ai didi

android - 在禁用 VERTEX_ARRAY 客户端状态的情况下调用 glDrawElements

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:02:56 25 4
gpt4 key购买 nike

我试图在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com