Transformations in allegro

I'm trying to port some code from processing, and I've found problems with the PushMatrix and PopMatrix. Example:

pushMatrix();
translate(x,y);
rotate(alfa);
translate(desx,desy);
image(bitmap,0,0);

pushMatrix();
translate(x,y);
popMatrix();

popMatrix();

Transformations in allegro are built as:

ALLEGRO_TRANSFORM t;

al_copy_transform(&old,&t);

al_intentity_transform(&t)
al_translate_transform(x,y);
al_rotate_transform(alfa);
al_use_transform(&t)

al_draw_bitmap(bitmap,0,0);

al_identity_transform(&old);
al_use_transform(&old);

It works perfectly with one bitmap, but I haven't foud a way to concatenate two transforms the same way as with pushMatrix, and I think I don't fully understand the behavior of allegro transformations.

Any tip or help will be wellcome.

Thanks!

Mark Oates

In AllegroFlare's placement2d, you get these two functions:

1void placement2d::start_transform() 2{ 3 ALLEGRO_TRANSFORM transform; 4 5 al_copy_transform(&previous_transform, al_get_current_transform()); 6 al_identity_transform(&transform); 7 8 al_translate_transform(&transform, -align.x*size.x, -align.y*size.y); 9 al_scale_transform(&transform, scale.x, scale.y); 10 al_translate_transform(&transform, anchor.x, anchor.y); 11 al_rotate_transform(&transform, rotation); 12 al_translate_transform(&transform, position.x, position.y); 13 14 al_compose_transform(&transform, &previous_transform); 15 16 al_use_transform(&transform); 17} 18 19 20 21 22void placement2d::restore_transform() 23{ 24 al_use_transform(&previous_transform); 25}

previous_transform is an ALLEGRO_TRANSFORM, member of placement2d