If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Question about CL_CollisionOutline

I want to create a class that has a draw() function and CL_CollisionOutline support. I thought this would be straight forward:

I created a class called Terra that is derived from CL_Surface and contains a CL_CollisionOutline object. I initialized the CL_CollisionOutline as new CL_CollisionOutline(get_pixeldata()) after I loaded the CL_Surface with data from a CL_ResourceManager.

The problem is that the CL_CollisionOutline(get_pixeldata()) doesn't seem to work as I expected. If I do a "draw()" on the CL_CollisionOutline i just get a vertical line.

If I explictly load the CL_CollisionOutline from a file (.png) it works, but not if I get the data from a PixelBuffer.

Any Ideas? Am I doing something wrong? Is there a standard way to "attach" a CL_CollisionOutline to a CL_Surface?

In outline_provider_bitmap_generic.cpp it will only operate on rgba8888 format, rather than any 32 bit format. We should probably fix this in ClanLib...

But for now, here are some work arounds.

When you use get_pixel_buffer() from a surface, unless the original pixel buffer was saved, it REBUILDS it by grabbing it from the video card - and instead of rgba, it's setup as the native ogl surface format, which is abgr.

So you've got two options at this point:

One is instruct the surface to KEEP the original pixelbuffer, this way it won't rebuild it and change its format: (makes the get_pixel_buffer() just return the original which is sitting in system memory, kind of a waste, but fast)

Now, if you didn't care about speed (I mean, it's initted once right? who cares.. still a lot faster than reloading the .png) and didn't want to waste the memory keeping the original around, you could convert the pixel buffer format on the fly like this:

Code:

//build the buffer from the video surface, then convert it to rgba
CL_CollisionOutline myOutline2(surface.get_pixeldata().to_format(CL_PixelFormat::rgba8888));

Great! Thanks for the quick reply, that does explain the problem and the workaround does work.

I do have another issue. I am using the resource manager to load surfaces and there is no place for the flag in the constructor. I can switch back away from the resource manager, but it would be a shame because it is really nice. How do you use the CL_CollisionOutline with the resource manager?

However, I think this may be a side effect of me not using the library correctly. The goal here is to have a CL_Surface that contains an Image and a CL_CollisionOutline that traces it. Then, the pixelbuffer of the surface is changed (imagine it describes the ground and a hole is blown into it) and the outline is updated. Rinse, Repeat.