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

标签 android opengl-es opengl-es-2.0

我试图在 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 - 如何从多个图像中绘制可绘制对象?

java - onClick 在 ListActivity 中使用 SimpleCursorAdapter

android:显示加载屏幕的最快方法

opengl-es - OpenGL ES 2 : Should I use glMultiTexCoord or glVertexAttribPointer?

android - LibGDX - 使用 OpenGL ES 2.0 的透视相机

opengl - 在 3D 表面上放置多个图像

android - 抽屉导航错误 : Not Being On Top, 标题未显示,第一部分重复

android - 在 FragmentTransaction 之后调用什么方法

ios - 渲染到纹理与渲染到 CAEAGLLayer 支持的 View ?

android - 三个相邻矩形的颜色连续变化