When I enable depth testing in my program I get this weird overlap effect. I gather it’s something to do with blending but I don’t know much about texture blending.
In the picture examples of my problem are circled.
Any help is much appreciated!
Thanks,
Rowan.
PS: As you can tell from the picture my top down tree sprites are awful. Do you know where I can get some the look decent.
Why shouldn’t a transparent object write to depth buffer?
Because then the algorithm doesn’t work.
If you draw something transparent into the depth buffer, and then draw something (transparent or opaque) behind it, OpenGL will dutifully not draw it at all.
OpenGL only knows about the triangle it’s currently rendering and the framebuffer. It doesn’t know what has been rendered “transparently” before.
This is a common, well-understand thing about transparency via blending. You must render all transparent objects last. You must turn off depth buffering, and you must sort transparent objects back-to-front. There is no other way to handle this.