0
\$\begingroup\$

How can I draw a static bitmap for the background of an Allegro 5 graphics window, if I'm using camera transformations to apply perspective to bitmaps in front of the background so it appears that they're otherwise in a 3D space?

If I try simply drawing a bitmap to the backbuffer without any transforms applied, and then call al_use_transform on a perspective transform when drawing the other objects, the "background" moves along with the transform.

\$\endgroup\$
1
\$\begingroup\$

What you describe should work. One common mistake is forgetting to reset the transform each time you draw the background.

You probably want something like this in your draw loop:

void draw() {
    ALLEGRO_TRANSFORM trans;
    al_identity_transform(&trans);
    al_use_transform(&trans);
    al_draw_bitmap(background, 0, 0, 0)

    al_translate_transform(&trans, 20, 20);
    al_use_transform(&trans);
    al_draw_bitmap(foreground, 0, 0, 0)
}

If you forget to apply the identity transformation before drawing the background, it will continue using whatever you set with the previous call to al_use_transform.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.