Results 1 to 6 of 6

Thread: Question about CL_CollisionOutline

  1. #1

    Default 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?

    -thanks

  2. #2

    Default test case

    In the following code, myOutline1 will draw, but myOutline2 will not.

    Code:
          CL_Surface surface("resources/rocket.png");
    
          CL_CollisionOutline myOutline1("resources/rocket.png");
          CL_CollisionOutline myOutline2(surface.get_pixeldata());
    
          while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) {
            CL_Display::clear(CL_Color(255, 255, 255, 255));
    
            surface.draw(10,10);
            myOutline1.draw(10, 100, CL_Color(200, 0, 0));
            myOutline2.draw(100, 100, CL_Color(0, 200, 0));    
    
            CL_Display::flip();
            CL_System::sleep(10);
            CL_System::keep_alive();
          }

  3. #3
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,345

    Default

    Ok, I took a look and here is what I found:

    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)

    Code:
    CL_Surface surface("resources/rocket.png", CL_Surface::flag_keep_pixelbuffer));
    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));
    Hope that helps.
    Last edited by Seth; 09-18-2006 at 02:02 AM.
    Seth A. Robinson
    Robinson Technologies

  4. #4

    Default

    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.

    Is this feasible with ClanLib?

    Great library, by the way. Keep it up.

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

    Default

    You can use an attribute called keep_pixelbuffer in the resources to get the same functionality.

    <surface .... keep_pixelbuffer="true">

    At least the code says so, haven't tested it

  6. #6

    Default Thanks

    Worked like a charm. Thanks!

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
  •