[Allegro 5] How to return the current target bitmap?
mzg147

I am making a function which is creating a new bitmap with circle on it, and returning that bitmap. Something like this:

#SelectExpand
1function(int w,int h,ALLEGRO_COLOR color) 2{ 3ALLEGRO_BITMAP* temp = al_create_bitmap(w,h); 4al_set_target_bitmap(temp); 5al_draw_filled_ball(w/2,h/2,(w>h)?(w/2):(h/2),color); 6return temp; 7}

But then i have an error, because and after i called this function target is non-exciting local bitmap "temp". I thought of it, and i had an idea. Is there a function which return pointer to current bitmap? Like this:

#SelectExpand
1function(int w,int h,ALLEGRO_COLOR color) 2{ 3ALLEGRO_BITMAP* current_target_bitmap = al_magic_function(); 4ALLEGRO_BITMAP* temp = al_create_bitmap(w,h); 5al_set_target_bitmap(temp); 6(...) 7al_set_target_bitmap(current_target_bitmap); 8return temp;

I couldn't find that sort of function. Maybe there is other way? The sending display to function is the last help, i really wanna this function to be self-sufficient. ???

kazzmir
Thomas Fjellstrom

I call for a vote. I think we should add al_magic_function() to the api.

What does it/should it do? MAGIC!

RPG Hacker
mzg147 said:

al_set_target_bitmap(current_target_bitmap);

Not sure of I missunderstood something, but doesn't this do nothing at all?

bamccaig

Not sure of I missunderstood something, but doesn't this do nothing at all?

It is perhaps named poorly. Basically he is making a backup copy of the current target bitmap (pointer), modifying the target bitmap temporarily, and then restoring it to the original form. You need to do this because Allegro 5 doesn't let you specify the bitmap to draw onto in the same call as you draw. You have to first "select" a bitmap and then draw. This basically means that you either have to always select a target before you draw anywhere, or when you do change the target you have to always make a backup and restore it when you're finished. ::)

RPG Hacker

Ah, now I see! Stupid me. I completely overlooked the decleration. Thought he did something like

al_set_target_bitmap(al_get_target_bitmap());

Thread #611973. Printed from Allegro.cc