Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Creating sub bitmap from display

This thread is locked; no one can reply to it. rss feed Print
Creating sub bitmap from display
limprevisible
Member #16,590
November 2016

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
Member #8,592
May 2007
avatar

limprevisible
Member #16,590
November 2016

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
Member #12,636
March 2011

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
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Member #8,592
May 2007
avatar

limprevisible
Member #16,590
November 2016

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
Member #8,592
May 2007
avatar

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.

Go to: