Z Order in 2D with orthographic projection and texture atlas
Posted
by
Carbon Crystal
on Game Development
See other posts from Game Development
or by Carbon Crystal
Published on 2012-10-28T23:27:41Z
Indexed on
2012/10/29
5:22 UTC
Read the original article
Hit count: 341
I am working with a 2D game in OpenGL ES and have a question about z-order together with a texture atlas.
I am using an orthographic projection because I want pixel-perfect rendering of 2D sprites, however from what I can determine the draw order is really the only thing that will determine which textures (sprites) appear above or below their neighbors.
That is, the "z-index" is a function of the order in which the textures are drawn as opposed to the z coordinate on the vertex array being drawn.
So.. I have a texture atlas to save binding multiple textures for each draw call but this immediately creates a problem if there is more than one atlas in play. If I need to draw textures from more than one atlas (typically the case if I have too many sprites to fit in a single atlas of a reasonable size), then I can't maintain a "draw order" across atlases unless I want to bind/unbind the atlas textures more than once.. which kinda defeats the purpose.
Does anyone have any clues as to what the best approach is here? Currently I'm running under an assumption that I will have to declare different fixed "depths" (e.g foreground, background etc) in my 2D scene and assume that the z-order for sprites at a given depth is the same. Then I can have as many atlases as I need at each depth and simply draw the depths in order (along with their associated atlases)
I'd love to hear what other people are doing.
© Game Development or respective owner