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.