Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_hold_bitmap_drawing

This thread is locked; no one can reply to it. rss feed Print
al_hold_bitmap_drawing
Josh Taylor
Member #17,070
April 2019
avatar

Well, I'm kind of new around here. First of all, I have to say Allegro 5 is great. I've only messed around a little with 4 in the past until I bit the bullet and tried out 5.

Here's my question:
Does al_hold_bitmap_drawing work with al_draw_bitmap_region? Or does it only apply to sub-bitmaps? I've searched the forums, and all I've concluded was: Maybe.

Here's the code I used it with:

#SelectExpand
1 al_hold_bitmap_drawing(true); 2 for (int y = sy; y < sy + y_tiles_in_view; y++) 3 { 4 for (int x = sx; x < sx + x_tiles_in_view; x++) 5 { 6 if ((x < MAP_WIDTH) && (x > -1) && (y < MAP_HEIGHT) && (y > -1)) 7 { 8 if (m->position[x + y * MAP_WIDTH].empty_tile == false) 9 { 10 //Draw the tile, subtracting the camera position 11 al_draw_bitmap_region(tile_sheet, 12 convert_index_to_pixel_xy(m->position[x + y * MAP_WIDTH].tile, 16, TILE_SIZE, RETURN_X), 13 convert_index_to_pixel_xy(m->position[x + y * MAP_WIDTH].tile, 16, TILE_SIZE, RETURN_Y), 14 TILE_SIZE, 15 TILE_SIZE, 16 (x * TILE_SIZE) - c->x, 17 (y * TILE_SIZE) - c->y, 18 0); 19 } 20 } 21 } 22 } 23 al_hold_bitmap_drawing(false);

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Josh Taylor
Member #17,070
April 2019
avatar

Thanks, Edgar! That's what I hoped to hear.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

So yes, your example is using al_hold_bitmap_drawing correctly. It's designed to work with atlas's and tile maps.

Things that would make it work less effectively include changing the source texture. So if you tried to draw many small independent bitmaps each with their own texture, the performance gain would be practically nil. Because each time the source texture changes, it has to rebind it with the gpu in order to draw from it.

Also to note, al_hold_bitmap_drawing does not work with primitive drawing. It's for bitmap drawing only.

Go to: