Blitting from bitmap to blitmap in Allegro 5
TeaRDoWN

I'm trying to get into how Allegro 5 works from using Allegro 4 for a couple of years now. One thing that has changed alot (if I understand it correctly) is how to draw what onto which bitmaps.
Therefor I've made a short example of some Allegro 4 bitmap operations and if someone would be able to write the exact same using Allegro 5 functions I would be very grateful.

#SelectExpand
1// Create screen buffer 2BITMAP *new_screen = create_bitmap(screen->w,screen->h); 3clear_to_color(new_screen, makecol(0,0,0)); 4 5// Load sprite 6BITMAP *sprite1 = load_bitmap("image.bmp", NULL); 7 8// Create secondary sprite 9BITMAP *sprite2 = create_bitmap(sprite1->w-10, sprite1->h-10); 10blit(sprite1, sprite2, 0,0, 5,5, sprite1->w-10, sprite1->h-10); 11 12// Draw secondary sprite centered on screen buffer 13draw_sprite(new_screen, sprite2, new_screen->w/2-sprite2->w/2, new_screen->h/2-sprite2->h/2); 14 15// Update screen 16draw_sprite(screen, new_screen, 0,0);

(I think I wrote it without build errors, didn't try in a compiler before :D)

Matthew Leverton

The new_screen is not needed, because Allegro 5 gives you a back buffer. By default, that back buffer is the target of all drawing operations. To change the target to a bitmap, use al_set_target_bitmap(bmp). To change back to the back buffer, use al_set_target_backbuffer(display).

Also, most structs are opaque, so you must use functions like al_get_bitmap_width(bmp) to retrieve information, as opposed to directly accessing struct members.

If you read the manual, you should find it pretty obvious how the various drawing related functions work.

TeaRDoWN

Ok, thanks.

I've read the manual but the information is divided into different areas and not always followed by a simple example I thought it could be handly to have it here on the forum - "this is how you did it before, this is how you do it now".

Matthew Leverton

Why don't you write the Allegro 5 version and see how close you get? If you get stuck, then ask some questions.

Thread #608511. Printed from Allegro.cc