Results 1 to 6 of 6

Thread: ClanLib and Graphic Layers

  1. #1
    Lesser Knight jmguy02's Avatar
    Join Date
    Apr 2009
    Location
    Georgia
    Posts
    43

    Default ClanLib and Graphic Layers

    How does, or can, ClanLib deal with layers when using graphics? (e.g. Layer1 = background.jpg, Layer2 = pic1.jpg, etc...)

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    If i'm understanding you correctly.

    We layer graphics using the alpha channel of the image to control the opacity.

    See ClanLib[0.8][0.9]/Examples/ShadowOfTheBeast

  3. #3
    Lesser Knight jmguy02's Avatar
    Join Date
    Apr 2009
    Location
    Georgia
    Posts
    43

    Default Not Exactly...

    Opacity adjustment isn't exactly what I was thinking of but I could sort of see where that might work to an extent. What I was thinking was more akin to layers in a graphic tool like Corel or Photoshop...

    For example: if you had a background image then you had buttons on top of that and then there might be a window that could pop up above the background and the buttons. In that instance if every object had an alpha of 255 how do you know what object shows on top of what? Layers allow you to specify the stacking order. So if an object is above (higher layer) another object then it would cover it.

    After thinking about adjusting opacity more.......I suppose that would work and code can just modify opacity on the fly. I might be able to create a routine to organize that in layers too using the opacity adjustment. That must be how it's done at a lower level than I'm accustom to. Thanks for your help.
    Last edited by jmguy02; 04-01-2009 at 03:22 PM.

  4. #4
    Lesser Knight jmguy02's Avatar
    Join Date
    Apr 2009
    Location
    Georgia
    Posts
    43

    Default Someone already had same question

    I found Alan Thorne's page where he was interested in the same application where he needed layers. Here's the link in case anyone runs across this need.

    http://www.alanthorn.net/clanlib/

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Thumbs up

    The "layers" is basically the draw order in clanlib.

    Lets say each of these functions draw the wanted elements, using CL_Sprites or whatever:

    DrawBackground();
    DrawButtons();
    DrawWindow();

    The order you call this is the order they appear on screen.

    If you want a specific layer system, isn't that just a std::vector<> of for instance CL_Sprites you want to draw on that layer?

    A rough sketch coded in a hurry:

    class SpriteElement
    {
    CL_Sprite sprite;
    CL_Point position;

    void Draw(CL_GraphicContext &gc)
    {
    sprite.draw(position.x, position.y, gc);
    }
    }

    class Layer
    {
    std::vector<SpriteElement *> sprites;

    void Draw(CL_GraphicContext &gc)
    {
    for(int i=0; i<sprites.size(); ++i)
    {
    sprites[i]->draw(gc);
    }
    }
    }

    class LayerManager
    {
    std::vector<Layer> layers;

    void Draw(CL_GraphicContext &gc)
    {
    for(int i=0; i<layers.size(); ++i)
    {
    layers[i]->draw(gc);
    }
    }
    }

  6. #6
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default

    As Sphair pointed out, you control your own drawing order.

    I used SpriteWorld back in my Mac coding days, and it had an elaborated sprite layering system -- which was ultimately just a linked list of things to draw in a particular order. But SW was C only, so it was useful then. With C++, it's not really necessary.

    It's very easy and manageable to do yourself. I use a "container" class which is mainly just a vector (or simple list) with some methods for updating and drawing each object in the container. Just call them in the order you want them drawn (farthest layer first), and that's it.

    Now if you're talking Y-sorting (or z-sorting), it's a little different, but still not too complex.

Similar Threads

  1. Graphic Memory Handeling
    By Haimon in forum Novashell Game Creation System
    Replies: 2
    Last Post: 01-19-2009, 02:48 PM
  2. SiS graphic error
    By Scriptiz in forum Novashell Game Creation System
    Replies: 7
    Last Post: 06-10-2007, 07:15 PM

Bookmarks

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
  •