[A5] how to use a bitmap as a pattern to fill a rectangular area?
axilmar

Hi, I'd like to fill a rectangular area with a bitmap used as a pattern. How do I do that with A5?

Don Freeman

Use the primitives addon. Look at the source code for the primitives example...

axilmar

Thanks. After lots of experimentation, I came up with this:

#SelectExpand
1void al_draw_bitmap_rect(ALLEGRO_BITMAP *bmp, int sx, int sy, int sw, int sh, float dx, float dy, float dw, float dh, int flags) { 2 ALLEGRO_BITMAP *sub = al_create_sub_bitmap(bmp, sx, sy, sw, sh); 3 ALLEGRO_BITMAP *clone = al_clone_bitmap(sub); 4 5 ALLEGRO_COLOR c = al_map_rgb(255, 255, 255); 6 7 ALLEGRO_VERTEX vertices[4]; 8 9 vertices[0].x = dx; 10 vertices[0].y = dy; 11 vertices[0].z = 0; 12 vertices[0].color = c; 13 vertices[0].u = 0; 14 vertices[0].v = 0; 15 16 vertices[1].x = dx + dw; 17 vertices[1].y = dy; 18 vertices[1].z = 0; 19 vertices[1].color = c; 20 vertices[1].u = dw; 21 vertices[1].v = 0; 22 23 vertices[2].x = dx; 24 vertices[2].y = dy + dh; 25 vertices[2].z = 0; 26 vertices[2].color = c; 27 vertices[2].u = 0; 28 vertices[2].v = dh; 29 30 vertices[3].x = dx + dw; 31 vertices[3].y = dy + dh; 32 vertices[3].z = 0; 33 vertices[3].color = c; 34 vertices[3].u = dw; 35 vertices[3].v = dh; 36 37 al_draw_prim(vertices, nullptr, clone, 0, 4, ALLEGRO_PRIM_TRIANGLE_STRIP); 38 39 al_destroy_bitmap(clone); 40 al_destroy_bitmap(sub); 41}

Am I doing it correctly? the visual output seems correct.

The function obviously creates and destroys bitmaps, so it's not the fastest thing. Other than pre-creating the bitmaps, is there another way to specify a subarea of the bitmap? perhaps using the vertices?

SiegeLord
axilmar said:

Other than pre-creating the bitmaps, is there another way to specify a subarea of the bitmap? perhaps using the vertices?

Can't be done without shaders, which is why Allegro doesn't support this operation.

axilmar
SiegeLord said:

Can't be done without shaders, which is why Allegro doesn't support this operation.

Thanks. So it seems I would have to actually split the bitmap into other bitmaps.

Thread #613849. Printed from Allegro.cc