Re: [AD] clipping, sub bitmaps

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> The A4 documentation for
> create_sub_bitmap reads: "... the origin
> point must lie within the parent region."
> 
> It seems like A4.9 has the same restrictions. Is there any
> way in 4.9
> to create a clipped, translated drawing area with an origin
> outside
> the target bitmap?
> 
> e.g., To create a 32x32 clipped virtual bitmap, where the
> bottom-right
> 16x16 pixels would lie in the top-left 16x16 pixels of the
> target
> bitmap, and the rest would be off-bitmap:
> 
> al_set_translation(-16, -16);
> al_set_clipping_rectangle(0, 0, 16, 16);  // if in
> relation to the
> real, untranslated coordinates
> al_set_target_bitmap(parent);
> al_draw_filled_rectangle(0, 0, 15, 15, white, 1); //
> actually drawn
> off bitmap to (-16,-16, -1,-1)
> al_draw_filled_rectangle(16, 16, 31, 31, black, 1); //
> drawn to
> top-left 16x16 of bitmap
> 
> or:
> 
> child = al_create_sub_bitmap(parent, -16, -16, 32, 32);
> al_set_target_bitmap(child);
> al_draw_filled_rectangle(0, 0, 15, 15, white, 1); //
> actually drawn
> off bitmap to (-16,-16, -1,-1)
> al_draw_filled_rectangle(16, 16, 31, 31, black, 1); //
> drawn to
> top-left 16x16 of bitmap
> 
> --
> Matthew Leverton

The transformations from the primitive addon can be used to accomplish this. E.g. your first example will look like:

ALLEGRO_TRANSFORM Trans;
al_build_transform(&Trans, -16, -16, 1, 1, 0);
al_use_transform(&Trans);

al_set_clipping_rectangle(0, 0, 16, 16);  // if in relation to the real, untranslated coordinates
al_set_target_bitmap(parent);
al_draw_filled_rectangle(0, 0, 15, 15, white, 1); //actually drawn off bitmap to (-16,-16, -1,-1)
al_draw_filled_rectangle(16, 16, 31, 31, black, 1); //drawn to top-left 16x16 of bitmap

Obviously, won't work with bitmaps or text though as those are not tied down to that system officially (in practice, it will work though, but it's undocumented).

-SiegeLord







Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/