Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I was wondering, I've only seen examples of OpenGL ES 2.0 where people have used one or perhaps two images. I didn't see multiple images of where they each had independent movement.

What if someone needed about 20 independent movable images/objects in their game?

Would that make for one huge shader, or would one make multiple shaders. And if one makes multiple shaders, how would you use them. I could use some pseudo-code or even better some snippets of real code to see how this would be done in a 2D game.

I've only seen examples of static arrays that are rendered to a screen. What's an example of multiple movable objects in ES 2.0?

share|improve this question

closed as not a real question by Byte56, msell, Anko, bummzack, Nate May 1 '13 at 21:21

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 1 down vote accepted

One option is having a vertex buffer describing the positions of the object's vertices, and then using something like glBufferSubData to update those positions to move them around. That could be generalized to having a way to update any particular attributes being sent to the vertex shader (color, opacity, transformation data, etc.).

So you'd create a buffer (glGenBuffers, glBindBuffer, glBufferData), write some vertex data into the buffer, and then when that data changes, use glBufferSubData to send those changes to the renderer. You'll need to look into setting up your attributes correctly so that your vertex shader knows what to do with that data, though, which is a whole other bit of work and could vary depending on what you want to do, look into glGetAttribLocation, glEnableVertexAttribArray, glVertexAttribPointer, stuff like that. You shouldn't need a separate shader for each new object; the attributes and uniforms you send to the shader would control their individual appearance.

share|improve this answer
    
Thank you very much, that clarifies a lot for me, would the same be true of adding vertices dynamically as the program is running? That would answer one of my other posted questions where I ask how to render a 3d model as its being made? –  mathacka May 1 '13 at 20:45
    
Yeah, you could do the same with additional vertices. You'd adjust the element count when calling glDrawElements, and adjust your buffer (and subsequent glBufferSubData call) to account for the extra vertex data. Also, as a side note, the order in which the verts in that buffer are used is defined by the element buffer (see GL_ELEMENT_ARRAY_BUFFER, as opposed to GL_ARRAY_BUFFER which was used when setting up the vertex data buffer) which will also need to be resized as new elements are added. –  Doug Kavendek May 1 '13 at 21:41
    
Thanks, you've been a great help. –  mathacka May 2 '13 at 11:50
    
I didn't fully understand the shader part of it until now, of course you could have a model/view/projection matrix variable in a shader that's reused for different transform now that I've studied more, and the Vertex data could essentially be 20 copies of the data into separate buffers. –  mathacka May 4 '13 at 4:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.