簡體   English   中英

如何在 Allegro 的屏幕中顯示子位圖的繪制?

[英]How to show the draw of subbitmap in screen in Allegro?

我使用兩個位圖,圖像(子位圖)和網格(主位圖)

ALLEGRO_BITMAP* grid = NULL;
ALLEGRO_BITMAP* image = NULL;
ALLEGRO_DISPLAY* display = NULL;

//Initialization
display = al_create_display(SCREEN_W, SCREEN_H + INFO_H);
grid = al_create_bitmap(SCREEN_W, SCREEN_H + INFO_H); 

al_set_target_bitmap(grid);
al_set_target_bitmap(al_get_backbuffer(display));

al_draw_bitmap(grid, 0, 0, 0);

//Creating a model
image = loadBitmapAtSize(...);
al_create_sub_bitmap(grid, 0, 0, columns, rows);
al_draw_bitmap(image, 0, 0, 0);

直到這里一切順利,但如果我直接繪制到圖像(子位圖),那么我找不到如何發送更改以顯示。

al_set_target_bitmap(image);

//rows and cols are the height and width of subbitmap
for (int y = 0; y < rows; ++y) {
    for (int x = 0; x < columns; ++x) {
        if(x == y || x-1 == y || x+1  == y || x == y-1 || x == y+1){
            //I test the condition and the program is entering to the if
            al_draw_pixel(x, y, al_map_rgb(255, 255, 255));
        }
    }
}

al_set_target_bitmap(grid);

al_flip_display();

知道如何在編輯子位圖后更新主位圖嗎?

從 Allegro 文檔:

子位圖是與預先存在的(父)位圖共享繪圖內存的位圖,但可能具有不同的大小和剪輯設置。

https://www.allegro.cc/manual/5/al_create_sub_bitmap

al_create_sub_bitmap返回一個指向ALLEGRO_BITMAP ,你需要分配給一個變量來使用。

要創建和分配您的子位圖,您可以使用:

ALLEGRO_BITMAP* subbitmap = al_create_sub_bitmap(grid, 0, 0, columns, rows);
al_set_target_bitmap(subbitmap);

您必須將“網格”位圖繪制到顯示器上,然后翻轉它。

al_set_target_backbuffer(display);
al_draw_bitmap(grid , 0 , 0 , 0);
al_flip_display();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM