PDA

View Full Version : CL_PixelBuffer transfer to another CL_PixelBuffer



RootKernel
10-03-2012, 07:55 AM
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


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)


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 !

sphair
10-03-2012, 09:06 AM
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)

RootKernel
10-03-2012, 09:24 AM
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

sphair
10-03-2012, 10:47 AM
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.

RootKernel
10-03-2012, 11:44 AM
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-1.0.0/Reference/html/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 :D ! Thanks for advices !