Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » How to show the draw of subbitmap in screen

This thread is locked; no one can reply to it. rss feed Print
How to show the draw of subbitmap in screen
temporadis
Member #17,414
February 2020

Hello,

I using two bitmaps, image (subbitmap) and grid (main bitmap)

#SelectExpand
1ALLEGRO_BITMAP* grid = NULL; 2ALLEGRO_BITMAP* image = NULL; 3ALLEGRO_DISPLAY* display = NULL;

#SelectExpand
1 //Initialization 2 display = al_create_display(SCREEN_W, SCREEN_H + INFO_H); 3 grid = al_create_bitmap(SCREEN_W, SCREEN_H + INFO_H); 4 5 al_set_target_bitmap(grid); 6 al_set_target_bitmap(al_get_backbuffer(display)); 7 8 al_draw_bitmap(grid, 0, 0, 0); 9 10 //Creating a model 11 image = loadBitmapAtSize(...); 12 al_create_sub_bitmap(grid, 0, 0, columns, rows); 13 al_draw_bitmap(image, 0, 0, 0);

Until here it is all going well, but If I draw directly to image(subbitmap) then I not found how to send the changes to display.

#SelectExpand
1 al_set_target_bitmap(image); 2 3 //rows and cols are the height and width of subbitmap 4 for (int y = 0; y < rows; ++y) { 5 for (int x = 0; x < columns; ++x) { 6 if(x == y || x-1 == y || x+1 == y || x == y-1 || x == y+1){ 7 //I test the condition and the program is entering to the if 8 al_draw_pixel(x, y, al_map_rgb(255, 255, 255)); 9 } 10 } 11 } 12 13 al_set_target_bitmap(grid); 14 15 al_flip_display();

Any idea how can I update the main bitmap after edit the subbitmap?

MikiZX
Member #17,092
June 2019

I cannot test this at the moment but it could help you:
al_create_sub_bitmap(...) actually returns a pointer value of ALLEGRO_BITMAP type which you (in your actual source) never store or use.
Once you obtain that pointer you need to use it with al_set_target_bitmap command.

So something like this (instead of line 12):

ALLEGRO_BITMAP *sub = al_create_sub_bitmap(grid, 0, 0, columns, rows);
al_set_target_bitmap(sub);
//draw to sub
//draw grid on screen

Also, you post parts of your source code (as opposed to full code of the example where you are reproducing the issue) so it is difficult to know what you are trying to do but for one, lines 5&6 are kind of canceling eachother out:

temporadis
Member #17,414
February 2020

Thanks for your response!

I deleted the following lines:

I try your recomendation for line 12:

    subImage = al_create_sub_bitmap(grid, 0, 0, columns, rows);
    al_set_target_bitmap(subImage);
    al_draw_bitmap(image, 0, 0, 0);

only obtain a black screen

But, when I try to draw the grid al_draw_bitmap(grid, 0, 0, 0), it produces an error:

_bitmap_drawer: Assertion `bitmap != dest && bitmap != dest->parent' failed.

Sorry for not post the entire code. The last part of the post sample code will run inside a while-loop.

MikiZX
Member #17,092
June 2019

Don't worry about not posting entire code. It is just that it would be easier to make it work for you if you did post a minimalistic example that reproduces the issue you have - you could get a better answer here if you did.

What is the issue at the moment, I believe, is that you are never drawing anything to 'display'. Once your grid, sub, ... bitmaps have been drawn to, you will need to:
al_set_target_bitmap(al_get_backbuffer(display));
and then draw those bitmaps on the screen (namely, I believe you need to draw the 'grid' bitmap to 'display') and then do the al_flip_display();.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You can't draw a bitmap onto itself.

Also, I answered your question on Stack Overflow.

Note : The 'Allegro Development' forum is for development of the Allegro library, not 'Programming Questions' which is for questions about use of Allegro.

Go to: