Jump to content
  • Advertisement
Sign in to follow this  
GenuineXP

OpenGL Avoiding the Painter's Algorithm: Using the Depth Buffer?

This topic is 3801 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 using OpenGL for the backend of my game engine and am wondering if somehow I can use the depth buffer (or some other feature) to control "depth" of drawing operations. Currently, my abstracted framework provides this functionality by basically sorting drawing operations by depth and then sending them to OpenGL. This is rather annoying and becomes hard to deal with when I need to combine things like hierarchical transformations with depth. Does OpenGL have some facility to control the "depth" of drawing operations in 2D? If my projections are setup properly, could I just translate things along the z-axis without any perspective correction to attain this effect? Ultimately, I'd like to be able to perform drawing operations in any order and preserve their depth. Is this possible? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Yes. Use an orthographic projection (or, as you called it, without any perspective), then just draw things with a z-component with depth testing enabled (it isn't by default).

Share this post


Link to post
Share on other sites
Quote:
Ultimately, I'd like to be able to perform drawing operations in any order and preserve their depth. Is this possible?


I'm not sure I understand your question, as that's exactly what the depth buffer is meant for.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
I'm not sure I understand your question, as that's exactly what the depth buffer is meant for.

I've only used OpenGL for very simple 3D programs, and mostly 2D graphics, so my knowledge of the depth buffer is virtually non-existant. :-)

I'll give the idea mentioned above a try. Thanks for the replies!

Share this post


Link to post
Share on other sites
You'll still have to use the painter's algorithm for partially transparent things (sprites like ghosts or smoke clouds).

If you draw a partially transparent pixel close to the camera, and then draw another pixel further away, the depth buffer prevents the second pixel from drawing at all, though logically you should be able to see through the first pixel to the second.

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!