Results 1 to 12 of 12

Thread: Using CL_SpriteDescription::add_gridclipped_frames

  1. #1

    Default Using CL_SpriteDescription::add_gridclipped_frames

    I'm having alot of trouble getting simple things like a sprite drawn to the screen.

    I am trying to use CL_SpriteDescription::add_gridclipped_frames, kindof like it's used in this example:

    desc_advanced.add_gridclipped_frames(CL_TargaProvi der::load("gridframes.tga"), 0, 0, 32, 32, 10, 2, 0, 0, true);

    I found this in http://clanlib.org/docs/clanlib-2.0....w/sprites.html, but this example seems outdated for 2.0.

    What is the proper way to use add_gridclipped_frames, or more specifically, the CL_Texture or CL_PixelBuffer as instructed here:

    http://clanlib.org/docs/clanlib-2.0....ed_frames.html

    ?

    What i'd like to do is pass it a filename for an image that has a 4x4 grid of sprites.

    Additionally, where can I find a few tutorials that are actually accurate for 2.0? The ones I am reading seem to be incorrect...

    Thanks!

    Flav
    Last edited by sphair; 07-31-2009 at 08:24 PM.

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

    Default

    I've updated the Sprites Overview to reflect recent API changes. I think it should compile now.

    Please try again, and let me know in detail if something goes wrong.

  3. #3

    Default

    I can't seem to find the changes. Where are they linked?

    Flav

  4. #4

  5. #5

    Default

    The line I was looking at seems to be the same. Did you modify something very subtle in it?

    Thanks!

    Flav

  6. #6

    Default

    The line compiles fine, I think my issue is elsewhere.

    I am getting an error:

    "Debug Error!

    <path to my exe>

    This application has requested the Runtime to terminate it in an unusual way. Contact support team blah blah blah"


    I stepped through with the debugger and it seems to crash in this line:

    FreeLibrary(module);

    I tracked it back a bit and this seems to be the most relevant line that lead to the above:

    CL_IODevice datafile = directory.open_file_read(filename);


    If there is any extra info I could supply to make the problem less vague please let me know=)


    Flav

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

    Default

    Can you attach a stripped down example source code, so we can look at it please?

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

    Default

    Do you surround your code with try/catch CL_Exception?

    try
    {
    code here...
    }
    catch (CL_Exception e)
    {
    #ifdef WIN32
    std::vector<CL_String> stackTrace = e.get_stack_trace();
    CL_String text = e.message + "\r\n";
    for (size_t i = 0; i < stackTrace.size(); i++)
    text += cl_format("\r\n#%1 %2", i, stackTrace[i]);

    MessageBox(0, text.c_str(), TEXT("Unhandled Exception"), MB_OK);
    #else
    CL_Console::write_line("Unhandled exception: %1", e.message);
    #endif

    return 1;
    }

  9. #9

    Default

    Sure, here is my code. It's not too tidy yet cuz all I'm doing is testing the features right now. And for the main I pretty much just added the draw functions to the HelloWorld example provided=).

    Also, please do let me know if something else is blatantly wrong. in particular, I'm completely guessing on how to handle CL_GraphicContext.

    I marked the lines that are culprits with //#########// (the lines are below that)

    It's in two files:

    ---
    Code:
    class Sprite { 
    
    public:
    
    	CL_SpriteDescription options;
    	CL_Sprite *graphic;
    	CL_GraphicContext *gc;
    
    
    	Sprite(CL_GraphicContext *gc_) {
    		gc = gc_;
    
    //#########//	
    options.add_gridclipped_frames(CL_TargaProvider::load("picture.png"), 0, 0, 32, 48, 4, 4, 0, 0, true);
        	graphic = new CL_Sprite(*gc, options);
    	}
    
    	void update() {
    		graphic->update();
    	}
    
    	void draw(int x, int y) {
    		graphic->draw(*gc, x, y);
    	}
    
    };
    Code:
    class DisplayProgram
    {
    public:
    	static int main(const std::vector<CL_String> &args);
    };
    
    // Create global application object:
    // You MUST include this line or the application start-up will fail to
    // locate your application object.
    CL_ClanApplication app(&DisplayProgram::main);
    
    int DisplayProgram::main(const std::vector<CL_String> &args)
    {
    	// Setup clanlib modules:
    	CL_SetupCore setup_core;
    	CL_SetupDisplay setup_display;
    	CL_SetupGL setup_gl;
    	
    	// Create a window:
    	CL_DisplayWindow window("Hello World", 640, 480);
    	
    	// Retrieve some commonly used objects:
    	CL_GraphicContext gc = window.get_gc();
    	CL_InputDevice keyboard = window.get_ic().get_keyboard();
    	CL_Font font(gc, "Tahoma", 30);
    	
    	//#########//
    	Sprite sprite(&gc); 
    
    	// Loop until user hits escape:
    	while (!keyboard.get_keycode(CL_KEY_ESCAPE))
    	{
    		// Draw some text and lines:
    		gc.clear(CL_Colorf::cadetblue);
    
    		sprite.update();
    		sprite.draw(10,10); 
    
    		CL_Draw::line(gc, 0, 110, 640, 110, CL_Colorf::yellow);
    		font.draw_text(gc, 100, 100, "Hello World!", CL_Colorf::lightseagreen);
    		
    		// Make the stuff visible:
    		window.flip();
    	
    		// Read messages from the windowing system message queue,
    		// if any are available:
    		CL_DisplayMessageQueue::process();
    		
    		// Avoid using 100% CPU in the loop:
    		CL_System::sleep(10);
    	}
    	
    	return 0;
    }
    Thanks for all the help!=)


    Flav

  10. #10

    Default

    Update: I tried catching the exception and it says "unsupported TGA filetype encountered".

    I figure it's talking about the image file, but I'm not sure why it's unsupported; it's just a png. I tried with a bmp as well, but no dice.

    Any suggestions?

    Flav

  11. #11

    Default

    Ha. I'm so sorry guys, VERY dumb mistake. Looks like only TGA filetype is supported. I never used TGA before so I didn't know what it meant by that=)

    I changed the format and it works. Thanks for all the help!=D

    Flav

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

    Default

    If you look at the changes I did in the Sprites overview, I replaced the targaprovider with the CL_ImageProviderFactory class instead, which loads TGA, PNG, JPG or any other image provider that is registered.

    You explicitely use the CL_TargaProvider, and of course it won't work with a PNG.

    use the CL_ImageProviderFactory class instead, or the CL_PNGProvider.

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
  •