title: Android opengl es 2.0 Vertex/Index Buffer not working
body: <p>I've got a shape I'm trying to draw through OpenGL ES 2.0 on Android 3.2. I can get my scene rendering as intended with DrawArrays and a FloatBuffer, but not through glGenBuffers and a vbo/ibo.</p>
  
  <p>Here are some snippets I'm using with irrelevant sections taken out</p>
  
  <pre><code>    GLES20.glGenBuffers(1, vbo, 0);
      GLES20.glGenBuffers(1, ibo, 0);
  
      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo[0]); 
      GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, this.vertexBuffer.capacity() * 4, vertexBuffer, GLES20.GL_STATIC_DRAW);
      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
  
      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo[0]);
      GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.capacity() * 2, indexBuffer, GLES20.GL_STATIC_DRAW);
      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
  </code></pre>
  
  <p>Above is my code for creating my arrays. Below is my code for rendering.</p>
  
  <pre><code>    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo[0]);
      GLES20.glEnableVertexAttribArray(positionHandle);
      GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, vertexBuffer);
      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo[0]);
  
      GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, 1, GLES20.GL_UNSIGNED_SHORT, 0);
  
      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
  </code></pre>
  
  <p>I know for a fact that my vertex float buffer is working correctly because If I replace the above code with the below code, it works as intended :</p>
  
  <pre><code>    GLES20.glEnableVertexAttribArray(positionHandle);
      GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, vertexBuffer);
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 3);
  </code></pre>
  
  <p>While I was debugging to find out if DrawArrays would work (which it does if I remove all code pertaining to binding buffers), I found that I could leave all the gen/bind/data buffer calls EXCEPT  *GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo[0]);*, this one exclusively would prevent rendering when using drawArrays</p>
  
  <p>I've spent all day trying changing little details and calls in different orders to no avail.</p>
  
  <p>At first I was trying to render a cube with the following data : 
  private float[] pts = {     -1f,    1f,     -1f,</p>
  
  <pre><code>                         1f,    1f,     -1f,
                           -1f,   1f,     1f,
                           1f,    1f,     1f,
                           -1f,   -1f,    -1f,
                           1f,    -1f,    -1f,
                           -1f,   -1f,    1f,
                           1f,    -1f,    1f };
  private short indecies[] = {0,1,2,3,6,7,4,5,0,1,1,5,3,7,7,6,6,2,4,0};
  </code></pre>
  
  <p>But I decided to go with this test data and this works in drawArrays without the use of the indicies</p>
  
  <pre><code>    private float[] pts = {     -1,0,0,
                              1f,0,0,
                              0f,1,0};
  private short[] indecies = {0,1,2};
  </code></pre>