Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glDrawElements is called with VERTEX_ARRAY client state disabled

I'm trying to draw a sphere in OpenGL ES 2.0+ on Android, and I'm seeing the following error in Logcat:

glDrawElements is called with VERTEX_ARRAY client state disabled!

I looked at the documentation for this call and I can't see anything I might be doing wrong. From the error it sounds like I'm missing some setup somewhere.

Here's my VertexBuffer class where I'm doing the setup:

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);
    }
}
like image 936
Christopher Perry Avatar asked Jan 07 '23 04:01

Christopher Perry


1 Answers

Add:

setEGLContextClientVersion(2);
like image 167
Sarbartha Sengupta Avatar answered Jan 18 '23 22:01

Sarbartha Sengupta