|
[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: 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: 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
|
Thomas Fjellstrom
Member #476
June 2000
|
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
Member #12,492
January 2011
|
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
|
RPG Hacker said: 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. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
RPG Hacker
Member #12,492
January 2011
|
Ah, now I see! Stupid me. I completely overlooked the decleration. Thought he did something like
|
|