Im working on an application for android that is using canvas operations to do all the drawing at the moment but Im switching everything over to opengles to gain performance. My only problem is I have no idea how to draw to screen a dynamically changing scene in opengles. I have a few questions so I guess Ill list them.
1.) How do I dynamically add onscreen objects based on a constantly changing list using opengles.
2.) Do I need to pass some kind of list/array/object container to the renderer or the GLSurfaceView itself.
3.) If I want to translate/move the objects according to an updated position how would I update the actual position vector in the container for each object.
I think you have the right idea already. I would pass your container to the renderer and on each
onDrawFrame(GL10)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.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.
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.
snippet of example code:
Bubble
Renderer