【问题标题】:How to show the draw of subbitmap in screen in Allegro?如何在 Allegro 的屏幕中显示子位图的绘制?
【发布时间】:2020-05-24 22:33:50
【问题描述】:

我使用了两个位图,图像(子位图)和网格(主位图)

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();

知道如何在编辑子位图后更新主位图吗?

【问题讨论】:

    标签: c++ allegro allegro5


    【解决方案1】:

    来自 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);
    

    【讨论】:

      【解决方案2】:

      您必须将“网格”位图绘制到显示器上,然后翻转它。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多