Problem with Depth-Test

Started by Cornix, June 03, 2013, 14:46:51

Previous topic - Next topic

Cornix

Hello,

I am making a 2D-Application and have the following problem right now:
I have 2 sets of sprites which need to be rendered. For each set individually I want to use the OpenGL depth-test to make sprites with higher Z-values appear "on top" of sprites with lower Z-values.
Additionally I want all sprites from the first set to always be rendered on top of sprites from the second set, no matter which one has higher Z-values.

Its obvious I cant just render both sets after each other because then there might be sprites from the second set with higher Z-values as sprites from the first.
I also dont want to sort the sprites myself because it might potentially be alot of sprites which are moving in their Z-coordinate every frame.
I also dont want to simply add a very high value to the Z of all sprites from the first set because maybe I will have even more sets then just 2 in the future.

What would be the cleanest and safest way to solve this?
How much performance would I lose with that solution?

Thank you very much.

Fool Running

QuoteI also dont want to simply add a very high value to the Z of all sprites from the first set because maybe I will have even more sets then just 2 in the future.
That seems the cleanest to me. If you add more sets, then just change the added values.

If you really don't want to do that, you can call glClear(GL_DEPTH_BUFFER_BIT) between sets. However, this will probably be much slower.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Cornix

Thanks for the response.

There is only a limited range of values for the Z-coordinates. And its not guaranteed that all sprites of the first set have a higher Z as all sprites of the second set just because I add a high number.
Its not a clean solution in my opinion and I would really like to avoid it.

The second option you mentioned seems good though. Havent even thought about that yet. Maybe I will give it a shot. How bad could the performance be? After all, its called once per frame anyways, isnt it?