Jump to content
  • Advertisement
Sign in to follow this  
john_t

2D depth

This topic is 4804 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

I'm having trouble figuring out how to deal with depth-related issues in a 2D scene. For instance, if I put an object on screen I want it to be drawn on top of--not behind--my background tiles. The easy way I've found to do this is simply to draw the tiles first and then draw the object on top of it. This works, but I can predict several problems with it. First, there's no way I can batch my DrawPrimitive calls; because the order of drawing is dependent on depth it cannot be sorted by texture or anything else, so each of my DrawPrimitive calls will consist of just 2 triangles (1 textured quad) and I'll be making a lot of unnecessary state changes. Second, because of the nature of my program I'm not sure it will always be possible to draw in order depth: this problem is probably surmountable of I'm careful but I'd rather not have to worry about it as a design consideration. Is there any way besides order of drawing by which I can specify the depth at which an object exists in a 2D environment?

Share this post


Link to post
Share on other sites
Advertisement
AS it seems you are drawing everything with texture quads, and I suppose that you've turned of the zbuffer etc.
I also suppose that you are using an OrthoLH Matrix. If so all of your objects appear on screen the same size in spite of the distance of the camera so you could set the vertices z-coords to any value between 0.0f and 1.0f in order to get them drawn in front or back of those with a larger/smaller z-coord.

So you could create a few virtual planes.

Hope this helps.

cheers,
Marcel

Share this post


Link to post
Share on other sites
Add:
Maybe you could give this a read. I didn't read it yet but the articles aim is this topic.

http://www.devmaster.net/articles/rendering_trees/


cheers,
Marcel

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!