PDA

View Full Version : Buffer in ClanLib



karaman
05-30-2008, 01:20 PM
Hi,

I have experience with SDL and want now make a background image made of sprites.

My questions:
*How can I create a image with specific size (CL_Surface doesn't have that sort of constructor, nor CL_Canvas)?
*I want to blit an image to an other, this should work with CL_Canvas, is that the best practise?

ClanLib is really the best 2D engine I saw, great job.

Thanks by advance.

knutsj
05-31-2008, 05:49 AM
Hi,

I have experience with SDL and want now make a background image made of sprites.

My questions:
*How can I create a image with specific size (CL_Surface doesn't have that sort of constructor, nor CL_Canvas)?
Yeah, it's kinda confusing that CL_Surface has no constructor for an empty surface of a given size. What you need to do is use CL_PixelBuffer:

CL_PixelBuffer apixelbuffer = CL_PixelBuffer(width, height, width*4, CL_PixelFormat::abgr8888);
CL_OpenGLSurface asurface = CL_OpenGLSurface(apixelbuffer);

or just

CL_OpenGLSurface asurface = CL_OpenGLSurface(CL_PixelBuffer(width, height, width*4, CL_PixelFormat::abgr8888));

(If you're using another pixel format, replace "width*4, CL_PixelFormat::abgr8888")
(I'm assuming this will work for SDL too)




*I want to blit an image to an other, this should work with CL_Canvas, is that the best practise?
You can do:

asurface.draw(acanvas.get_gc());

I don't really know if this is the best way to do it or not.


Also, if you're working with sprites you should probably take a look at the CL_Sprite class.

karaman
05-31-2008, 09:00 AM
It works, great. Thanks!