Jump to content
  • Advertisement
Sign in to follow this  
GenuineXP

2D Scene Graphs: Applying Transformations AND Depth Sorting?

This topic is 4191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have no experience with scene graphs, but I've decided I want to implement one for my 2D engine. I know layers are often used for 2D applications, but they have some limitations and scene graphs seem to have some very useful abilities (for example, they could be useful for game entities composed of many moving, rotating sprites). The problem is, how can a scene graph apply translations, rotations, effects, etc., while also sorting/ordering drawing operations for correct depth? Is this even possible? I've found several useful articles about scene graphs, but they're all in terms of 3D applications (where the actual order in which drawing operations occur doesn't necessarily affect the depth/ordering of objects). My engine uses hardware support (via OpenGL currently), so is there a way I could employ the depth buffer to nullify the effect of the order in which drawing operations are performed? For now, I want to keep things very basic (a graph can apply simple translations and rotations, and that's about it). I've reviewed a few recommended patterns in the GoF's Design Patterns just to be sure I'm on my toes for this. :-) Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You don't necessarily have to draw the sprites while you're traversing the graph. I would do the scene graph step first. Store the result for each sprite in a list with a reference to the sprite the result was for. Sort the list accordingly, then draw. The implementation details are up to you.

If you're using the opengl depth buffer, then it shouldn't matter in which order you are drawing unless you're using transparency or you're somehow using the entire precision range of the depth buffer, in which case you'll have to clear it multiple times per frame, but I find this extremely unlikely for a 2D application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!