开发者

Open GL ES - Z order when rendering 2D sprites

I was wondering if there was a way to make OpenGL ES render a batch of quads (rendered with texture page changes) and render them in z order (or reverse).

Note I don't want a ZBuffer, I just want quads rendered in or开发者_运维技巧der of zDepth.

Now I know people will say just render them in order, well I render grouped by texture page. However as you can imagine there are some cases where sprites from one texture page need to appear in front of another. When you only render on a texture page sort this causes a problem.

So I was wondering if I assigned the quads a z order would OpenGL ES respect this?

Any help greatfully received.

Cheers Rich


You cannot achieve what you want without Z Buffer / Depth Buffer.. What you are asking is the Depth Buffer's work done without enabling it !!

When Z buffer is enabled,everytime OpenGL draws to a pixel.. it checks the pixels existing Z value and then decides on whether to draw it or not.

When Depth Buffer is not enabled it simply overwrites irrespective of what z value of previous existing pixel was.


yes, you can definitely do this, as long as you

glEnable(GL_DEPTH_TEST);

and, of course, get a bunch of other things right. (be sure you create a depth buffer, use z values that are in the range of your view frustum...)


OpenGL ES won't do this for you. It will respect the order you specify, i.e. the order in which the quads are from the draw call. If you want them to render your quads sorted by Z, you'll have to sort them yourself prior to sending to OpenGL ES.

If you're using an index buffer, you can obviously sort just the indices. But you still have to compute the actual Z yourself.

Edit: Regarding your texture concern, I should add that to use different textures at the same time, you should look at using texture atlases (that is, a single texture that holds the various textures you want to use in different parts).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜