Jump to content
  • Advertisement
Sign in to follow this  
ColdFusion00

OpenGL Depth

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

Advertisement
You can enable depth testing, and use a depth value (assuming you're working with the standard horizontal X axis, and vertical Y axis, Z would be the depth).

Alternatively, you can set the depth writing to less than or equal, and sort all of the sprites before you render them. It requires a little more work, but if you plan on using Open GL for more complex rendering jobs, this type of knowledge will help further down the line.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gorax
You can enable depth testing, and use a depth value (assuming you're working with the standard horizontal X axis, and vertical Y axis, Z would be the depth).

Alternatively, you can set the depth writing to less than or equal, and sort all of the sprites before you render them. It requires a little more work, but if you plan on using Open GL for more complex rendering jobs, this type of knowledge will help further down the line.


Yes, glEnable for depth test and then adding a clear for the depth buffer seems to do the job nicley, for basic shapes, now if it will work with textures too , i this might just work :)

EDIT:
but theres one issue that annoys me a bit, when 2 shapes have the same z, gl draws them in reverse order. how do i get rid of that.

[Edited by - ColdFusion00 on August 22, 2010 11:12:00 PM]

Share this post


Link to post
Share on other sites
It's just a matter of what sprite get's drawn first.
You could also set the z value to a slightly different value like 0.000001 (assuming your sprites should be at a z-value of 0.

assainator

Share this post


Link to post
Share on other sites
Quote:
Original post by ColdFusion00
but theres one issue that annoys me a bit, when 2 shapes have the same z, gl draws them in reverse order. how do i get rid of that.
You can change the depth test. The 'regular' one is less-than-or-equal-to, where when pixels share the same z-value, the last one to be drawn will be visible. You could also use less-than, which will make the first pixel drawn with that z-value visible instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
Quote:
Original post by ColdFusion00
but theres one issue that annoys me a bit, when 2 shapes have the same z, gl draws them in reverse order. how do i get rid of that.
You can change the depth test. The 'regular' one is less-than-or-equal-to, where when pixels share the same z-value, the last one to be drawn will be visible. You could also use less-than, which will make the first pixel drawn with that z-value visible instead.


Yes, that works :)
EDIT: another problem, when i draw 2 textures with transparency, when i draw a texture after another with lower z , it gets drawn under like i would expect but there is a black box instead of transparency.

[Edited by - ColdFusion00 on August 24, 2010 12:01:45 AM]

Share this post


Link to post
Share on other sites
With alpha blending, you have to sort your objects (CPU side) from furthest to closest. You've got to do this in 3D or 2D.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
With alpha blending, you have to sort your objects (CPU side) from furthest to closest. You've got to do this in 3D or 2D.


Could you show me how i would sort a list. and wouldnt having to sort a list every frame cause slowdowns?

Share this post


Link to post
Share on other sites
You could tell a bit more about the game you're making.
I don't think that you need to sort the sprites in every frames. Do they change their depths/drawing orders?

So, what king of game you're making?

And another thing: before you start to play around with blending:
Do you have semi-transparent things, or just fully transparent and fully opaque?
If so: use alpha test instead.

google the words printed in bold.

Share this post


Link to post
Share on other sites
Why not ditch the z coordinate and just use glvertex2i?

Here's a lib I made that you can peruse to do easy 2d in GL.

http://rel.betterwebber.com/junk.php?id=115

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!