Results 1 to 9 of 9

Thread: CL_PixelBuffer drawing

  1. #1

    Default CL_PixelBuffer drawing

    Hello.

    I attempt draw tile map based on some graphical data from wrl file. I extract tiles 64x64 and store in CL_PixelBuffers. Next I calculate tiles count on screen and draw using CL_GraphicContext::draw_pixels.
    But I have strange behavior when I need draw small part of pixel buffer. For example I have screen height 480 and current vertical position = 438, I need draw only half tile:
    CL_PixelBuffer pb = wr.getMapBuffer(1,1); // get 64x64 pixel buffer
    gc.draw_pixels(100,gc.get_height() - 32, pb, CL_Rect(0,0,64,32)); // draw only 32 pixels from top of tile
    it doesn't work - nothing happened.
    But if I create new pixel buffer with size 64x32 it works:
    CL_PixelBuffer pbTarget(64,32,CL_TextureFormat::cl_rgb8);
    pb.convert(pbTarget, CL_Rect(0,0,64,32), CL_Rect(0,0,64,32));
    gc.draw_pixels(100,gc.get_height() - 32,pbTarget, CL_Rect(0,0, 64, 32));
    What I'm doing wrong? I don't want create special target buffer each time when I need draw tile near screen border.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Assuming you are using OpenGL (clanGL or clanGL1)

    Avoid using gc.draw_pixels(), it only exists for clanSWRender. It's very slow on OpenGL

    Method 1)
    CL_Image image(gc, pixelbuffer, pixelbuffer.get_size());
    image.draw(gc, xpos, ypos);
    (remember to only calculate image once in the program, opengl upload is slow)

    Method 2) (Advanced - Takes advantage of batch drawing, since all images are part of the same texture)
    CL_TextureGroup texture_group(1024, 1024);
    std::vector<CL_Image> images;
    ... For each pixelbuffer
    CL_Subtexture subtexture = texture_group.add(gc, CL_Size(32, 32);
    subtexture.get_texture().set_subimage( subtexture.get_geometry().get_top_left(), pixelbuffer, pixelbuffer.get_size() );
    images.push_back(CL_Image(gc, subtexture));
    ...
    image[offset].draw(gc, xpos, ypos);

  3. #3

    Default

    Thanks,

    Where I can get more info about CL_TextureGroup?

  4. #4

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

    Default

    Something like this might work as well:

    Code:
    // in loading
    CL_SpriteDescription desc;
    foreach pixelbuffer you've extracted
         desc.add_frame(pixelbuffer);
    CL_Sprite sprite(gc, desc);
    
    // in main loop
    sprite.set_frame(tile_index),
    sprite.draw(gc, xpos, ypos);
    Don't worry about drawing outside screen, it clips.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Sphair's method is much much better.

    Also, if you scale the tiles and get artifacts:
    pixelbuffer = CL_PixelBufferHelp::add_border(pixelbuffer, 1, pixelbuffer.get_size());
    can be used to stop colour bleeding at the edge problems.

  7. #7

    Default

    Thanks a lot.

    sphair,
    your solution is very good. I have to implemented it.

    I realized CL_TextureGroup is simple container for CL_Texture objects. When I create texture group I set initial texture size and if I attempt to store subtexture larger than initial size it will increasing.
    All subtextures store in binary tree and contain reference to parent texture and own rect in this texture. It's correct?
    I have to understand CL_TextureGroup is obsolete object? - because CL_Sprite I think much simplier.

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    CL_Sprite uses CL_TextureGroup inside "CL_Sprite_Impl::create_textures"

    CL_TextureGroup is probably for advanced users. .. so you can have CL_Image's and CL_Font glyphs in same CL_Texture

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

    Default

    Texturegroup is a class that packs small textures together efficiently. It is, as rombust says, a class for a very specific, advanced use.

Similar Threads

  1. CL_PixelBuffer question again...
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-22-2011, 06:50 AM
  2. CL_PixelBuffer Problem.
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 01-20-2011, 06:42 PM
  3. CL_PixelBuffer::get_pixel()
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-20-2011, 04:51 PM
  4. operate CL_PixelBuffer as CL_Surface
    By DavinciZhe in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 11-12-2009, 06:05 PM
  5. CL_PixelBuffer::get_pixel() weird results...
    By Otto (Strange) Halmén in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 12-06-2006, 07:36 AM

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
  •