allegro5
allegro5 copied to clipboard
feature request: al_draw_tiled_pixmap()
I wanted to make this feature myself and submit it as a patch, but I haven't been able to wrap my head around shaders yet.
It's a really simple feature though. It would just be something like void draw_tiled_pixmap(ALLEGRO_BITMAP *bmp, float x, float y, float w, float h);
. It would just repeatedly draw the bitmap on a grid, where the grid matches the geometry parameters passed. I understand that GLSL is very similar to C, so this feature would probably use the % operator to loop through the pixels of the bitmap while drawing it. It would really help with performance when it comes to drawing textures like bricks on a house, for example.
(there's also other people who would like a feature like this, like this person on stackoverflow)
Thanks for all your hard work!
You could probably implement this with al_draw_prim. It already has support for drawing tiled textures. You would just have to calculate the proper texture coordinates.
Edgar
On 11/23/2022 9:20 AM, sammonius wrote:
I wanted to make this feature myself and submit it as a patch, but I haven't been able to wrap my head around shaders yet.
It's a really simple feature though. It would just be something like |void draw_tiled_pixmap(ALLEGRO_BITMAP *bmp, float x, float y, float w, float h);|. It would just repeatedly draw the bitmap on a grid, where the grid matches the geometry parameters passed. I understand that GLSL is very similar to C, so this feature would probably use the % operator to loop through the pixels of the bitmap while drawing it. It would really help with performance when it comes to drawing textures like bricks on a house, for example.
(there's also other people who would like a feature like this, like this person on stackoverflow https://stackoverflow.com/questions/29174484/how-to-repeat-a-bitmap-with-allegro-5)
Thanks for all your hard work!
— Reply to this email directly, view it on GitHub https://github.com/liballeg/allegro5/issues/1387, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF2JBYJYY6VXGOCNSRWOMSTWJYY5RANCNFSM6AAAAAASJCT4IE. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Ok, thanks.
If you don't mind, I'd like to keep this open. I think it's a good idea. Yes, you can do this using the primitives addon, but that applies to every al_draw_*_bitmap
function (which is why #1003 exists). We'd probably call it al_draw_tiled_bitmap
or something.
Oh, ok. To be honest, I have no idea how to do it with a primitive, but I just thought I'd figure it out later and close the issue to be polite.
Here's the way you do it with primitives addon:
void draw_tiled_pixmap(ALLEGRO_BITMAP *bmp, float x, float y, float w, float h)
{
ALLEGRO_COLOR white = al_map_rgb_f(1., 1., 1.);
ALLEGRO_VERTEX vtx[] = {
{x , y , 0., 0., 0., white},
{x + w, y , 0., w , 0., white},
{x + w, y + h, 0., w , h , white},
{x , y + h, 0., 0., h , white},
};
al_draw_prim(vtx, NULL, bmp, 0, 4, ALLEGRO_PRIM_TRIANGLE_FAN);
}
Ok, thank you.
btw, is better if for the original bitmap also support size, position, rotation, and tint.