Results 1 to 10 of 10

Thread: [OpenGL 2.0] Depth buffer problems

  1. #1

    [OpenGL 2.0] Depth buffer problems

    Hello there.

    Instead of describing the problem, let me show you a picture, which I believe is more than words.
    http://i54.tinypic.com/2du07tc.jpg

    The problem is that one sprite overlaps the other. How do I keep them on the same level? I have the depth testing disabled + blending is enabled.

    Regards.

  2. #2
    Quote Originally Posted by Brainer
    How do I keep them on the same level?
    How do you imagine this?

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Isn't it simply in the order that they were drawn? Because I've never come across any that 'overlap' - or at least not literally anyway.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4
    Quote Originally Posted by Brainer View Post
    Hello there.

    Instead of describing the problem, let me show you a picture, which I believe is more than words.
    http://i54.tinypic.com/2du07tc.jpg

    The problem is that one sprite overlaps the other. How do I keep them on the same level? I have the depth testing disabled + blending is enabled.

    Regards.
    I'm not sure it is even possible to do what you want...

    Without depth testing, the last drawn sprite will always overlap the first drawn sprite.

    With depth testing, depending on the depth test check, either of the 2 sprites will again overlap the other one.

    cheers,
    Paul

  5. #5
    Can you try to draw how it is supposed to look?
    A i see it if they were on the same level they would collide with each other.
    http://3das.noeska.com - create adventure games without programming

  6. #6
    Quote Originally Posted by noeska View Post
    A i see it if they were on the same level they would collide with each other.
    Yes, that's basically what I'm trying to achieve.

    EDIT
    Or maybe you could tell me how do I bring one sprite on front of the other once it was rendered already? Hm, maybe not the best descriptive way of telling you about the problem, that's why take a look at these two images:
    http://i52.tinypic.com/2rff2bt.jpg and http://i56.tinypic.com/2d91qf9.jpg
    What I mean is that no matter which sprite I choose, it's drawn on top of the other ones.
    Last edited by Brainer; 26-11-2010 at 06:38 PM.

  7. #7
    Do you have a specific reason to use depth buffer for 2D rendering? It is slower than normal and regarding your problem it would be easily solved with drawing order. When depth buffer is disabled, what sprite is drawn last will show on top of others. You can disable the buffer on the fly too to draw just that 1 sprite on top of others.
    glDisable(GL_DEPTH_TEST)

  8. #8
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    A sprite is a sprite, there is no depth, so I don't follow what you are thinking of. If it were 3D then it might make some sense, but as you are working with flat 2D sprites all you can really do is 2D tricks such as blending, ADD, OR, XOR and so on.

    If you want specific sprites to overlap over another then it's simply a matter of drawing order and you have to adjust that so that it is drawn last somehow. The use of a depth buffer seems like a waste of resources to do such things though.

    ...also, is this an iOS app I see? Very nice. Good work.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  9. #9
    Yeah, you both were right. Using layers helped me solve the problem. Thanks a lot!

  10. #10
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Hey don't sweat it. Sometimes we all look for complicated solutions when a simple one would have sufficed. I've done this on many an occasion. I'm really starting to notice in some of my older projects from a few years back now.
    Jason McMillen
    Pascal Game Development
    Co-Founder





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •