PDA

View Full Version : [OpenGL 2.0] Depth buffer problems



Brainer
25-11-2010, 06:19 PM
Hello there. :)

Instead of describing the problem, let me show you a picture, which I believe is more than words. :)
http://i54.tinypic.com/2du07tc.jpg

The problem is that one sprite overlaps the other. How do I keep them on the same level? I have the depth testing disabled + blending is enabled.

Regards. :)

Andru
25-11-2010, 07:27 PM
How do I keep them on the same level?
How do you imagine this? :)

code_glitch
25-11-2010, 09:30 PM
Isn't it simply in the order that they were drawn? Because I've never come across any that 'overlap' - or at least not literally anyway. :D

paul_nicholls
25-11-2010, 09:35 PM
Hello there. :)

Instead of describing the problem, let me show you a picture, which I believe is more than words. :)
http://i54.tinypic.com/2du07tc.jpg

The problem is that one sprite overlaps the other. How do I keep them on the same level? I have the depth testing disabled + blending is enabled.

Regards. :)

I'm not sure it is even possible to do what you want...

Without depth testing, the last drawn sprite will always overlap the first drawn sprite.

With depth testing, depending on the depth test check, either of the 2 sprites will again overlap the other one.

cheers,
Paul

noeska
25-11-2010, 09:48 PM
Can you try to draw how it is supposed to look?
A i see it if they were on the same level they would collide with each other.

Brainer
26-11-2010, 06:32 PM
A i see it if they were on the same level they would collide with each other.
Yes, that's basically what I'm trying to achieve.

EDIT
Or maybe you could tell me how do I bring one sprite on front of the other once it was rendered already? Hm, maybe not the best descriptive way of telling you about the problem, that's why take a look at these two images:
http://i52.tinypic.com/2rff2bt.jpg and http://i56.tinypic.com/2d91qf9.jpg
What I mean is that no matter which sprite I choose, it's drawn on top of the other ones.

User137
26-11-2010, 11:33 PM
Do you have a specific reason to use depth buffer for 2D rendering? It is slower than normal and regarding your problem it would be easily solved with drawing order. When depth buffer is disabled, what sprite is drawn last will show on top of others. You can disable the buffer on the fly too to draw just that 1 sprite on top of others.
glDisable(GL_DEPTH_TEST)

WILL
27-11-2010, 01:08 AM
A sprite is a sprite, there is no depth, so I don't follow what you are thinking of. If it were 3D then it might make some sense, but as you are working with flat 2D sprites all you can really do is 2D tricks such as blending, ADD, OR, XOR and so on.

If you want specific sprites to overlap over another then it's simply a matter of drawing order and you have to adjust that so that it is drawn last somehow. The use of a depth buffer seems like a waste of resources to do such things though.

...also, is this an iOS app I see? :) Very nice. Good work. ;)

Brainer
27-11-2010, 01:16 PM
Yeah, you both were right. Using layers helped me solve the problem. :) Thanks a lot!

WILL
27-11-2010, 02:04 PM
Hey don't sweat it. :) Sometimes we all look for complicated solutions when a simple one would have sufficed. I've done this on many an occasion. I'm really starting to notice in some of my older projects from a few years back now. :P