Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A better way to communicate between other threads in your app and your GL thread / renderer is to keep your instance of your renderer to hand in your activity:</p> <pre><code>public class stackoverflowTest extends Activity { GLSurfaceView glSurface; MyRenderer myRenderer; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); glSurface = (GLSurfaceView)findViewById(R.id.glSurfaceView1); myRenderer = new MyRenderer(); glSurface.setRenderer(myRenderer); Square mySquare = new Square(); myRenderer.addSquareToScene(mySquare); } } </code></pre> <p>and then in your renderer</p> <pre><code>public class MyRenderer implements Renderer { private Vector&lt;Square&gt; scene; private Vector&lt;Square&gt; bufferedSquaresToAddToScene @Override public void onDrawFrame(GL10 gl) { while(bufferedSquaresToAddToScene.size()&gt;0){ scene.add(bufferedSquaresToAddToScene.remove(0)); } for(int i = 0;i&lt;scene.size();i++){ scene.get(i).draw(gl); } } public void addSquareToScene(Square square){ bufferedSquaresToAddToScene.add(square); } } </code></pre> <p>To communicate back in the other direction, it is a bit harder for non-UI threads, but to the UI/main thread you can just use <a href="http://developer.android.com/reference/android/os/Handler.html" rel="nofollow">Handler</a></p> <p>And yes, it should be fairly easy to do a hashmap instead of a vector so you don't load in duplicate squares</p> <p><a href="http://www.anddev.org/post107733.html#p107733" rel="nofollow">As for confusion...</a></p>
 

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