views:

662

answers:

3

Hi,

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 order 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

A: 

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...)

David Maymudes
He is talking about the order of the draws, not that they respect the Z buffer. What he's asking is usually to have particles blend correctly (and requires reverse Z order)
Bahbar
I think he wants z order but he doesn't want to re-sort his drawing code in z-order because he's grouping by texture for performance.
David Maymudes
A: 

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).

Bahbar
A: 

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.

Quakeboy