Results 1 to 2 of 2

Thread: How can you draw a sprite or a surface onto another surface?

  1. #1
    Knight
    Join Date
    Feb 2009
    Location
    I looked through my window, there are no signs ... but, its definitely planet Earth.
    Posts
    88

    Default How can you draw a sprite or a surface onto another surface?

    I tried everything and the only class that has get_gc() is CL_Canvas, but its not working, it crashes when formed level map surface must be created from drawn canvas:

    CL_ResourceManager resource = CL_ResourceManager( tileresourcefile );
    CL_Sprite tilesprite = CL_Sprite( tilespritename.c_str(), &resource );

    char *tokenPtr;
    int tmp;

    int map_pos_x = 0;
    int map_pos_y = 0;

    while( !levelFile.eof() ) {
    levelFile >> tmp;
    //cout << tmp;
    tilesprite.set_frame( tmp );
    tilesprite.draw( map_pos_x, map_pos_y, canvas.get_gc() );

    if( map_pos_x == Width ) {
    map_pos_x = 0;
    map_pos_y += tileHeight;
    } else {
    map_pos_x += tileWidth;
    }
    }

    _levelMap = new CL_Surface( canvas.get_pixeldata() ); // this is where the crashing starts


    Here's call stack:

    #0 004468BA CL_PixelBuffer::get_width(this=0x427bf58) (pixel_buffer.cpp:89)
    #1 00412597 CL_OpenGLTarget::create_surface(this=0x3db728, provider=@0x22f420, flag=0) (opengl_target.cpp:70)
    #2 0043C848 CL_Surface::CL_Surface(this=0x4278ef0, provider=@0x22f520, flag=0) (surface.cpp:59)
    #3 00404F5A CLevel::CreateLevel(this=0x22fa80, levelNum=1) (C:/useful/wxWidgets/samples/projekat ClanLib Rebelium/CLevel.cpp:101)
    #4 004045F8 CGame::PlayTheGame(this=0x22fa70) (C:/useful/wxWidgets/samples/projekat ClanLib Rebelium/CGame.cpp:81)
    #5 004044D0 CGame::Run(this=0x22fa70) (C:/useful/wxWidgets/samples/projekat ClanLib Rebelium/CGame.cpp:64)
    #6 005B31D8 Rebelium::main(this=0x658010, argc=1, argv=0x3db168) (C:/useful/wxWidgets/samples/projekat ClanLib Rebelium/App.cpp:78)
    #7 0041228E WinMain(hInstance=0x400000, hPrevInstance=0x0, lpCmdLine=0x241f2f "", nCmdShow=10) (Win32/clanapp.cpp:84)
    #8 005A68EA main() (c:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_list.h:1164)

    it crashed at Display\pixel_buffer.cpp line 89 (return impl->width


    I'm hammering my head with this for 2 days, will I ever be able to finish this game? You made things to be simple and I should be able to follow even with low knowledge of C++. I have experience with SDL and there I was able to draw one surface, or part of one surface, onto another surface and form and position the map before flipping. While your classes allow me greater flexibility and makes other things easier, I don't understand how to do this.

  2. #2
    Knight
    Join Date
    Feb 2009
    Location
    I looked through my window, there are no signs ... but, its definitely planet Earth.
    Posts
    88

    Default

    Ok, when its done like this it works:

    CL_PixelBuffer pixelbuffer = CL_PixelBuffer(Width, Height, Width*4, CL_PixelFormat::rgba8888);
    _levelMap = new CL_Surface( pixelbuffer );
    CL_Canvas canvas = CL_Canvas();
    canvas.select_surface( *_levelMap );

    It appears that surface needs to be created from pixel data and then assigned to the canvas, while I was doing it the other way around.

Similar Threads

  1. draw surface onto another surface before drawing portion to the screen
    By alexv1 in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 02-25-2009, 12:19 PM
  2. about button surface
    By DavinciZhe in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 11-06-2007, 03:49 AM
  3. Surface Rotation
    By madmark in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 07-20-2007, 08:42 AM
  4. The fastest way to draw pixel by pixel?
    By Otto (Strange) Halmén in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 12-06-2006, 07:32 AM
  5. Blank Surface
    By ART_Adventures in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 09-23-2006, 12:14 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
  •