The best way to move sprites in OpenGL is to translate or change vertices.

I am creating an Android application using openGL ES. I am trying to draw in 2D a lot of moving sprites that bounce around the screen.

Consider that I have a ball at 100 100 coordinates. The ball graphic is 10 pixels wide, so I can create vertices boundingBox = {100,110,0, 110,110,0, 100,100,0, 110,100,0}and do the following in each loop onDrawFrame()with the loaded texture of the ball.

//for each ball object
FloatBuffer ballVertexBuffer = byteBuffer.asFloatBuffer();
ballVertexBuffer.put(ball.boundingBox);
ballVertexBuffer.position(0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, ballVertexBuffer); 
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0,4);

Then I updated the array boundingBoxto move the balls around the screen.

As an alternative, I could not change at all bounding boxand instead the translatef()ball before drawing the vertices

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, ballVertexBuffer); 
gl.glPushMatrix();
gl.glTranslatef(ball.posX, ball.posY, 0);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0,4);
gl.glPopMatrix();

What would be best done with effective and best practices.

+5
2

OpenGL ES ( 2.0) instancing, . , 2- sprite instanced N , x/y , , , , ( ES ). , .

, ( )... :
2 VBOs, , - . , -, , glBufferData(... 0) , OpenGL, , .

, , (, ). , , .

+3

, . , glTranslate , , 4 × 4, 64 16 .

, - - instancing.

+1

All Articles