0

下面的代码不起作用;它会产生一个空白屏幕。但是,如果我将填充的矩形线朝底线更改为:

    al_draw_filled_rectangle(100, 100, 100+15, 100+15, al_map_rgb(155, 255, 155));

它在正确的坐标处产生一个正方形。这是怎么回事?

    #define ALLEGRO_STATICLINK



     #include <allegro5/allegro.h>
     #include <allegro5/allegro_primitives.h>



    int main(int argc, char **argv)

{
    ALLEGRO_DISPLAY *display;


    if(!al_init())
    {
         return -1;
    }

    display = al_create_display(640, 480);
    if(!display)
    {
        return -1;
    }

    if(!al_init_primitives_addon())
    {
        return -1;
    }


    al_draw_filled_rectangle(73, 493, 73+15, 493+15, al_map_rgb(155, 255, 155));

    al_flip_display();

    al_rest(10);

    return 0;
}
4

1 回答 1

4

您正在尝试在大于屏幕高度的 Y 坐标处绘制...

al_draw_filled_rectangle(73, 493, 73+15, 493+15, al_map_rgb(155, 255, 155));

平局 493 至 493+15

493 > 480 和 493+15 > 480

display = al_create_display(640, 480);

这将 480 设置为您的屏幕高度,因此在该数字上方绘制将导致不显示任何内容。

当你使用

al_draw_filled_rectangle(100, 100, 100+15, 100+15, al_map_rgb(155, 255, 155));

你现在实际上在屏幕上,所以它可以工作。

于 2012-03-06T00:55:15.690 回答