How to change contents of vertexbuffer used in glDrawArrays method in opengles

I have several triangular polygons and draw them in the traditional way: (android-java code)

gl.glDrawArrays(GL10.GL_TRIANGLES, i, j);

I want to update the coordinates of the vertices of the triangles. All the training materials that I found use the initial vertex data, and then apply only the transforms to them. I need to change each vertex coordinate independently.

I modify the contents of the array that is used to create the associated vertex buffer, but it does not make any changes on the screen. Re-building the vertex buffer on each frame seems correct.

Can you provide some sample source code if you know any?

+3
source share
3 answers

, glBufferSubData. , , , glBufferSubData .

, . , glBufferData .

+6

, java-android. @jerry , java- :

; Renderer Android GL10 , , , opengl-es1.1, gl.

public void onDrawFrame(GL10 gl) {
   GL11 gl11 = (GL11)gl;    

, opengl-es1.1, , .

java opengl-es. java Buffer, java java.nio .

public static FloatBuffer createFloatBuffer(float[] array){     
    ByteBuffer byteBuf = ByteBuffer.allocateDirect(array.length * 4);
    byteBuf.order(ByteOrder.nativeOrder());
    FloatBuffer fbuf = byteBuf.asFloatBuffer();
    fbuf.put(array);
    fbuf.position(0);
    return fbuf;
}

. . put(index, value) .

draw() , . vertexBuffer - FloatBuffer. , .

public void draw(GL11 gl) {

    vertexBuffer.put(index, floatValue);
    gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, 0, vertexBuffer.capacity(),vertexBuffer);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

    gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

}

, .

+1

, , , glBindBuffer()

-1

All Articles