Traditionally one just organizes one's tiles such that they are rendered
from back-to-front, with either alpha test or alpha blending, depending on
how your sprites were designed to be combined.

The depth buffer is primarily useful when individual meshes may be
self-intersecting, two meshes mutually overlapping, or other such exotic
situation that naturally arises in 3D. Rendering in 2D, the depth buffer is
usually overkill, and plain old sorting is both cheaper and more reliable.

It also greatly simplifies tile management of one can arrange them in
layers. Say, an opaque terrain layer, an alpha-tested layer for trees or
environmental props, and an alpha-blended layer for characters and npcs...

- Tristam
On Mon, Dec 7, 2015 at 5:55 PM Josh <[email protected]> wrote:

> So, this problem comes up a lot in programming 2D games, and I've been
> wrestling with it for several days. What I've realized is there seems to be
> no good solution. The issue is that sprites generally have some transparent
> areas. If you use depth buffering, whatever is behind the sprites will be
> written into those transparent areas, which will in turn mask every other
> sprite. The result looks like this:
>
>
> <https://lh3.googleusercontent.com/-k5Jk1EkLrt0/VmYzgn73JaI/AAAAAAAAAOk/UD54jOvOG9s/s1600/tree.jpg>
>
>
> The background "sticks" to the transparent areas of the tree sprite. I can
> choose not to render transparent areas with
>
>  glEnable(GL_ALPHA_TEST)
>  glAlphaFunc(GL_GREATER, .5)
>
> but unless your game is using pixel art, sprites are going to have some
> translucent areas that will still pick up the background and cause ugly
> outlining:
>
> So this isn't ideal. You can use a huge number of ordered groups and keep
> switching the group when sprites move. (I've found you have to then set
> groups for x placement as well, otherwise two sprites with equal x
> placement will randomly decide which one is in front every frame. For a big
> world, this is definitely a huge number of groups.) Or you can set
> collision boxes and game rules so no two sprites ever overlap.
>
>
> The ideal solution would be to enable depth buffering, draw a bunch of
> sprites to a buffer (against a transparent background), disable depth
> testing, draw your backgrounds to a second buffer, then draw the first
> buffer into the second. But I have no idea how to do this. Any advice
> appreciated!
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pyglet-users.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to