Setting depth
  • BarlingBarling October 2011
    Does anyone know how to set sprite depth? Or "z-index" value?
    Let's say I have three items:
    Desk, Pencil, and Paper.

    I want the Desk to be drawn under everything.
    The paper will be drawn over the desk, and the pencil over the paper.

    Of course you do this by coding whatever order the render calls are in,

    Desk->Render();
    Paper->Render();
    Pencil->Render();

    but what if I wanted to change it during run-time?

    What if I dropped the paper and it went under the desk?
    Paper->setDepth(Desk->getDepth(-1));

    Is this possible?
  • BarlingBarling October 2011
    Ah thanks.
    How exactly does it work though...?
    I mean to render something under something else, you have to put
    the Render() call before the second Render() call. How does this function do it?
  • ProfEclipseProfEclipse October 2011
    When you enable the z-buffer (System_SetState with HGE_ZBUFFER, true), then sprites with higher z-values draw above sprites with lower z-values (or lower over higher, I can't remember off the top of my head) regardless of render order.
  • kvakvskvakvs October 2011
    Usually when i was making my games, I disable HGE_ZBUFFER and just render everything ordered from back to front. This is easy due to the way I'm storing my level data. This gives signifficant speed up on older video cards (back to year 2000).

    Heard that modern cards don't give a flying zbuffer, if you enable or disable it, they work almost same fast.

    And if you go with enabled zbuffer, it is full 32bit float value in range from 0 to 1, you can go as many layers as you like up to 5-6 or even 7 digits after point.
  • BarlingBarling October 2011
    Yeah but what I'm asking is, how does it technically do it?
    I mean you'd first do one Render() to render something, and then you'd make another line in your code and add another Render() to put something else on top of the previous thing you rendered.

    How exactly does using Z() work? I mean this is run-time when it's called.
    It can't just change the source code and re-order your lines of code during run-time.
    That's where I'm confused on. Just how it works.
  • kvakvskvakvs October 2011
    This is basics of 3D rendering, and since HGE uses Direct3D inside, the principle applies to HGE too.

    When you start graphics, your video card creates special buffer in its memory, which contains a depth value for each pixel of screen. When video card renders something, each pixel is compared with its own depth value and is either skipped completely, or written, and depth value is updated.

    This works for 3D, but again HGE is based on 3D drawing just with special camera settings, making all drawn stuff to be parallel to the screen plane.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Tagged

Who's Online (0)