Results 1 to 9 of 9

Thread: Layer-based rendering in OpenGL

  1. #1

    Layer-based rendering in OpenGL

    Hello everyone.

    Take a look at the picture:

    I hope the effect I want to achieve is clear after looking at the picture. How do I do that in OpenGL?

  2. #2

    Re: Layer-based rendering in OpenGL

    So player character is drawn behind the tree? There are 2 ways i can think of:

    1) Treat player character and game objects same way and draw them Y-sorted.

    2) Cut tree image in pieces where lower part of tree that player collides to is drawn in terrain layer and higher tree part is drawn in upper layer after terrain and player.

  3. #3

    Re: Layer-based rendering in OpenGL

    Quote Originally Posted by User137
    1) Treat player character and game objects same way and draw them Y-sorted.
    Can you elaborate upon this one?

  4. #4

    Re: Layer-based rendering in OpenGL

    This question actually doens't have anything to do with OpenGL. It's more of a high-level thing. It can be done on any graphics library.

    1) Treat player character and game objects same way and draw them Y-sorted.
    I think he means that you make a list of drawable objects and sort them by Y-coordinate.
    Beware that the Y coordinate must denote the "base" of an object, where it touches the ground (e.g the trunk of a tree or the feet of a human player etc).
    Objects with a lower "base" (the trunk of the tree is lower than the feet of the guy) will overlap objects with a higher "base" (higher = closer to the top of the screen).

    Hope you get the idea.



    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #5

    Re: Layer-based rendering in OpenGL

    Aw, I get it now.

    But how could it be done in OpenGL?

  6. #6

    Re: Layer-based rendering in OpenGL

    Could not you use the z-buffer for that? I.e. enable depth buffer and set proper z coords for player background trees etc.
    http://3das.noeska.com - create adventure games without programming

  7. #7

    Re: Layer-based rendering in OpenGL

    Z-buffer would probably work, but i think sorting and drawing yourself is better for this kind of game. It has the following advantages over z-buffers:

    > It uses less Video-RAM and CPU/GPU power than Z-buffering.
    > You have to sort anyway when you want to use transparency, so why not do it from the beginning.
    > No Z-fighting artifacts
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  8. #8

    Re: Layer-based rendering in OpenGL

    My first thought was to divide the whole map into three layers:
    Layer 1 - holds the background tiles (i.e. grass, water, sand, etc.)
    Layer 2 - holds the characters
    Layer 3 - holds other scenery objects (buildings, trees, rocks, etc.)

    But I don't have any idea how to do something like that. I mean, render the layers so that one overlaps another. Just a thought, but maybe assign each layer a different Z coordinate. So the first layer would be, say, (0;0;0), the second (0;0;1), and the last one (0;0;2).

    What do you think?

    EDIT Hehe, basically what noeska suggested.

  9. #9

    Re: Layer-based rendering in OpenGL

    Basically my 1) suggestion consist of only 1 layer that is ground level terrain. After that draw players, trees, rocks, walls as sprites, spell effects on top of it. Simple quads for which you can use vertex arrays or whatever to optimize. These sprites are sorted by their Y-coordinate, but only sort visible sprites so calculation isn't going slow. Maybe a entirely separate list for visible objects that is updated as screen and objects move.

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
  •