Results 1 to 5 of 5

Thread: CL_PixelBuffer transfer to another CL_PixelBuffer

  1. #1

    Default CL_PixelBuffer transfer to another CL_PixelBuffer

    Hello !

    I'm doing a map loader system with ClanLib
    the map is defined in a XML file, it has different tilesets (PNG: a collection of 16*16 tiles)
    So i stored these tilesets in a CL_PixelBuffer, and to recreate the map, I want to paste the tile from the tileset on another CL_PixelBuffer for the map

    I have a function to retrieve the tile of a tileset having is id
    Code:
    CL_PixelBuffer                  Tileset::get_gid(int gid)
    {
      CL_PixelBuffer                copy;
      int                           x;
      int                           y;
    
      x = gid % width * 16 + (gid % width) * spacing + margin;
      y = gid / width * 16 + (gid / width) * spacing + margin;
      copy = this->tileset.copy(CL_Rect(x, y, x + 16, y + 16));
      return copy;
    }
    In the main loop for loading tiles of the map (simplified)
    Code:
    CL_PixelBuffer        *map = new CL_PixelBuffer(width * 16, height * 16, cl_rgba8); //Is this correct ?
    while (!element.is_null())
    {
    CL_PixelBuffer                tile;
    
    tile = <tileset>.get_gid(element.get_attribute_int("gid", 0));
    
    tile.transfer(*map, Xposition, Yposition);
    
    }
    So my question is to know how to transfer a CL_PixelBuffer to another one in a specified area.

    I tried map.upload_data(tile.get_data(), CL_Rect(...)), but it doesn't seem to work :P

    Thanks !

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

    Default

    Is there any special reason you have to be working with pixelbuffers?

    Could an alternative be to just load the tilesets into CL_Sprite's (it has support for grid cutting from a source for instance), and render them directly onto the screen?

    Or, if you want to compose a texture consisting of the entire map so it can be drawn using a single call, maybe use Render-to-texture using a CL_FrameBuffer? (See Canvas example)

  3. #3

    Default

    Quote Originally Posted by sphair View Post
    Is there any special reason you have to be working with pixelbuffers?

    Could an alternative be to just load the tilesets into CL_Sprite's (it has support for grid cutting from a source for instance), and render them directly onto the screen?

    Or, if you want to compose a texture consisting of the entire map so it can be drawn using a single call, maybe use Render-to-texture using a CL_FrameBuffer? (See Canvas example)
    No special reasons, just it's the first thing i saw on the doc :P

    You just point it out the goal is to draw just one thing for the map (good idea ? or loop all CL_Sprite and display them to right position is more efficient ?)

    I'll test Canvas, juste can you explain a little bit more this sentence :
    "It is recommended to limit the amount of canvas objects in the application. Every canvas require construction of a new OpenGL context, and canvases consume frame buffer memory."

    Thanks for your help

    PS : Is Canvas still available ? I included <ClanLib/display.h> but the compiler said :
    src/Map.h:15: erreur: ‘CL_Canvas’ does not name a type
    Last edited by RootKernel; 10-03-2012 at 10:13 AM.

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

    Default

    I would try first to just draw every tile using a CL_Sprite every frame. Check out the example Examples\Game\TileMap for an example.

    CL_Canvas is no longer available. The class that provides this is CL_FrameBuffer, and as I said, check out the Canvas example for how to do this.

    "It is recommended to limit the amount of canvas objects in the application. Every canvas require construction of a new OpenGL context, and canvases consume frame buffer memory."

    In your case, if you decide to go with this route, you'd just have on canvas for the screen anyway.

  5. #5

    Default

    Quote Originally Posted by sphair View Post
    I would try first to just draw every tile using a CL_Sprite every frame. Check out the example Examples\Game\TileMap for an example.

    CL_Canvas is no longer available. The class that provides this is CL_FrameBuffer, and as I said, check out the Canvas example for how to do this.

    "It is recommended to limit the amount of canvas objects in the application. Every canvas require construction of a new OpenGL context, and canvases consume frame buffer memory."

    In your case, if you decide to go with this route, you'd just have on canvas for the screen anyway.
    Sorry I found the CL_Canvas example here : http://www.clanlib.org/docs/clanlib-...CL_Canvas.html and I just figure out it was not the example you were talking about :O (v1.0.0)

    I'll try my luck with CL_Sprite, thanks !

    I did it ! Thanks for advices !
    Last edited by RootKernel; 10-03-2012 at 01:59 PM. Reason: problem resolved

Similar Threads

  1. CL_PixelBuffer drawing
    By intser in forum Official ClanLib SDK Forums
    Replies: 8
    Last Post: 12-07-2011, 09:40 PM
  2. CL_PixelBuffer question again...
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-22-2011, 06:50 AM
  3. CL_PixelBuffer Problem.
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 01-20-2011, 06:42 PM
  4. CL_PixelBuffer::get_pixel()
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-20-2011, 04:51 PM
  5. operate CL_PixelBuffer as CL_Surface
    By DavinciZhe in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 11-12-2009, 06:05 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
  •