Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [Allegro 5] How to return the current target bitmap?

This thread is locked; no one can reply to it. rss feed Print
[Allegro 5] How to return the current target bitmap?
mzg147
Member #14,899
February 2013

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
Member #1,786
December 2001
avatar

Thomas Fjellstrom
Member #476
June 2000
avatar

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

What does it/should it do? MAGIC!

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

RPG Hacker
Member #12,492
January 2011
avatar

mzg147 said:

al_set_target_bitmap(current_target_bitmap);

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

bamccaig
Member #7,536
July 2006
avatar

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
Member #12,492
January 2011
avatar

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

al_set_target_bitmap(al_get_target_bitmap());

Go to: