Creating sub bitmap from display
limprevisible

Hello guys,

I try to use the al_create_sub_bitmap from the my current display but it doesnt work. I constantly have that output:

Assertion failed: bitmap != dest && bitmap != dest->parent, file C:\dev\allegro_winpkg\universal\allegro\src\bitmap_draw.c, line 34

The only I found to bypass this problem is to copy the full display in an another bitmap then make my saving from this saved bitmap. Here is my trick:

1) al_set_target_bitmap(save_bitmap)
2) al_draw_bitmap(display, 0, 0, 0);
3) al_set_target_bitmap(display);
4) al_create_sub_bitmap(save_bitmap, .....);

Could like to bypass all this and use al_create_sub_bitmap directly from display.

Any idea would be appreciated thank you :)

Edgar Reynaldo

You could use al_draw_bitmap_region. Why do you need a sub bitmap of the display? You can set a clipping rectangle as well if that's what you're worried about.

limprevisible

I am creating a map with tiles.

Lets say that I have one tile representing the ground. The tile next to it will be the coast (composed by half part ground and the other one water). So what I do is:

1) Save half of the ground
2) Paste the ground on water
3) Paste the coast

So I will have at the end a tile composed by ground - coast - water.

So that's why I need to save a region of the display.

I will try the al_draw_bitmap_region and let you know :)

=> I tried with the al_draw_bitmap_region and still the same:

Assertion failed: bitmap != dest && bitmap != dest->parent, file C:\dev\allegro_winpkg\universal\allegro\src\bitmap_draw.c, line 34

beoran

The way I solve this in my tile map engine is to draw the tile partially by applying a mask to the tile before drawing it. See here https://gitlab.com/beoran/eruta-bs/blob/master/src/tile.c#L508 for how I do it. This is IMO easier than messing with the screen, and also gives better performance. On contemporary architectures, reading from the screen is slow.

SiegeLord

That assertion means that you can't draw a bitmap to itself, it's not specific to the display bitmap. The reason why that's forbidden is because, if I recall correctly, this operation isn't actually hardware accelerated. Basically you want to use an intermediate bitmap (there shouldn't be any speed penalty for this) and you should avoid reading from the display.

Edgar Reynaldo

You don't need the screen to do this. Do it on a buffer or temporary bitmaps instead.

limprevisible

Indeed I tried with a temp bitmap and it worked totally fine. Pity that we cant copy directly from the display.

Thanks by the way guys.

Edgar Reynaldo

You should be able to copy from the display directly. Problem is you're reading data from the GPU and the memory has to be locked. You can't draw from the screen to the screen however, if that's what you're doing.

Thread #616651. Printed from Allegro.cc