Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you have the right idea already. I would pass your container to the renderer and on each <code>onDrawFrame(GL10)</code> call, iterate through the container and perform the drawing. It might be worth synchronizing over the container as well if you are going to add objects dynamically.</p> <p>In terms of moving the objects. I assume that you will have image textures as well as an array of vertices defining a rectangle over which the texture should be drawn. You could, for each object, store the vertices of the rectangle. When 'moving' the objects I would probably recommend you simply alter the value of the vertices instead of using translate. </p> <p>Perhaps It would be helpful if you provided a bit more information about what sort of things you are trying to draw and when/how you want to add new objects.</p> <p>snippet of example code:</p> <p><strong>Bubble</strong></p> <pre><code>public class Bubble{ float[] boundingBox; int textureNumber; Bubble(int n){ textureNumber = n; boundingBox[0] = 0; boundingBox[1] = 100; boundingBox[2] = 0; boundingBox[3] = 100; boundingBox[4] = 100; boundingBox[5] = 0; boundingBox[6] = 0; boundingBox[7] = 0; boundingBox[8] = 0; boundingBox[9] = 100; boundingBox[10] = 0; boundingBox[11] = 0; } </code></pre> <p><strong>Renderer</strong></p> <pre><code>ArrayList&lt;Bubble&gt; bubbles; FloatBuffer bubbleVertexBuffer; onSurfaceCreated(..){ ByteBuffer bb = ByteBuffer.allocateDirect(12*4); bb.order(ByteOrder.nativeOrder()); bubbleVertexBuffer = bb.asFloatBuffer(); } onDrawFrame(GL10 gl){ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glColor4f(0.0f, 1.0f, 0.0f,0.0f); int size = bubbles.size(); for(int i = 0; i &lt; size; i++){ Bubble b = bubbles.get(i); bubbleVertexBuffer.put(b.boundingBox); bubbleVertexBuffer.position(0); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, bubbleVertexBuffer); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0,4); } } gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload