In my program I load bitmap from file (source) and I want to copy it and display copy on the screen each time mouse button pressed. I pasted making copy and displaying bitmap, but it doesn't work. Displaying original works in my code.
while( true )
{
ALLEGRO_EVENT event;
al_wait_for_event( queue, &event );
if( event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE )
{
destroy( queue, source, display );
al_destroy_bitmap( copy );
return 0;
}
if( event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN )
{
if( copy )
al_destroy_bitmap( copy );
copy = al_create_bitmap( al_get_bitmap_width(source), al_get_bitmap_height(source) );
al_set_target_bitmap( copy );
al_draw_bitmap( source, 0, 0, 0 );
al_flip_display();
}
}
I've found a solution already, to do a deep-copy of bitmap : ALLEGRO_BITMAP* al_clone_bitmap( BITMAP* source) function can be used.
while( true )
{
ALLEGRO_EVENT event;
al_wait_for_event( queue, &event );
if( event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE )
{
destroy( queue, source, display );
al_destroy_bitmap( copy );
return 0;
}
if( event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN )
{
if( copy )
al_destroy_bitmap( copy );
copy = al_clone_bitmap( source );
al_draw_bitmap( copy, 0, 0, 0 );
al_flip_display();
}
}