简体   繁体   English

Allegro 5-使用Alpha通道创建自定义位图

[英]Allegro 5 - creating a custom bitmap with alpha channel

Afternoon everyone, 大家下午

I was wondering if there's any way I could create a custom bitmap with alpha channel 我想知道是否可以通过Alpha通道创建自定义位图

bitmap = al_create_bitmap(30, 30);
al_set_target_bitmap(bitmap);
al_clear_to_color(al_map_rgb(255,255,255));
....
al_draw_tinted_bitmap(bitmap, al_map_rgba(0, 0, 0, 0.5),  X,  Y, 0);

I'm sure that I'm either not creating or drawing the bitmap correctly, so I could really use some advice. 我确定我没有正确创建或绘制位图,所以我可以使用一些建议。

Thanks in advance, Alex 预先感谢Alex

The only thing wrong with your code snippet is: 您的代码段唯一的错误是:

al_map_rgba(0, 0, 0, 0.5)

should be: 应该:

al_map_rgba_f(0, 0, 0, 0.5)

The former range is an integer from 0 to 255. 前一个范围是0到255之间的整数。

Also, keep in mind that Allegro's default blender is pre-multiplied alpha . 另外,请记住,Allegro的默认搅拌器是预乘alpha So if you wanted to tint red at 50%, you'd use: 因此,如果您想将红色调为50%,则可以使用:

float a = 0.5;
... al_map_rgba_f(1.0 * a, 0.0 * a, 0.0 * a, a) ...

If you're not thinking about it, you're probably assuming it's interpolating. 如果您不考虑它,则可能会假设它是插值的。 ie, the more intuitive blender for most people seems to be: 即,对于大多数人而言,更直观的搅拌器似乎是:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA)

but that is not the default for the reasons mentioned in the above link. 但这不是默认值,原因是上述链接中提到的原因。

after I set the 我设定了

al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

it allowed me to draw my "bouncer" bitmap and change its alpha channel using the below function: 它允许我绘制“弹跳器”位图并使用以下功能更改其Alpha通道:

al_draw_tinted_bitmap(bouncer, al_map_rgba_f(1, 1, 1, alpha) 40, 0, 0);

This previously did not work , so I guess adding the al_set_blender solved the "mistery". 以前这是行不通的,所以我想添加al_set_blender解决了这个“难题”。

Thanks for all your help. 感谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM