|
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)
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. 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: 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: al_set_target_bitmap(grid); al_set_target_bitmap(al_get_backbuffer(display));
|
temporadis
Member #17,414
February 2020
|
Thanks for your response! I deleted the following lines: al_set_target_bitmap(grid); al_set_target_bitmap(al_get_backbuffer(display)); 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: |
Edgar Reynaldo
Major Reynaldo
May 2007
|
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. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|