I know to make the variable itself is something like this
ALLEGRO_COLOR red = al_map_rgb(255,0,0);
but I notice if I put that line at the top the color will not appear to something in drawing in the game loop. Also, when i move that line right above the gameloop it works.
I am wondering if I can make the above line a global variable because im using it all over the place
I did try making a separate header and putting that above line in it and trying to call it in the main function but it didnt appear. Also, putting it outside above the main function didnt work either.
This the general idea:
/* define it outside of any function */ static ALLEGRO_COLOR red; int main() { /* initialize before first use (and after calling al_init()) */ red = al_map_rgb(255,0,0); }
You might want to give it a name that isn't tied to the color though, like "line_color" or "rocket_color". But it depends on how you use it.
If you want it to be available to more than just a single file, remove "static" from the definition and put extern ALLEGRO_COLOR red; in some header file that you then include where you want to use the symbol.
You can't call Allegro functions before initializing the library, which happens after main() is run, so any lines like that cannot be made global. You can make the variable global and have a function that runs after you initialize Allegro that contains color assignments.
There's also al_color_name("red") using the x11 color names.
Alright, thanks guys for the info
You can't call Allegro functions before initializing the library, which happens after main() is run, so any lines like that cannot be made global.
I use the color functions to define symbols globally, they work prior to initialization.
I have:
with a bunch of other color stuff.
I use the color functions to define symbols globally, they work prior to initialization.
I haven't looked at how those functions are implemented, but I'd say that you're simply lucky that they do work for you prior to initializing Allegro. Such behavior isn't guaranteed to work, and clearly doesn't for imgregduh.
Those do happen not to require initialization, but it's undocumented and shouldn't be relied on. I could very easily change al_color_name to require Allegro to be initialized without breaking any valid programs by simply using a slightly different code path.
Mark Oates said:
I use the color functions to define symbols globally, they work prior to initialization.
I haven't looked at how those functions are implemented, but I'd say that you're simply lucky that they do work for you prior to initializing Allegro. Such behavior isn't guaranteed to work, and clearly doesn't for imgregduh.
Actually, the way that Mark did it, it works. It seems that namespace is doing the trick
Actually, the way that Mark did it, it works. It seems that namespace is doing the trick
No, it is not. As I said, it just so happens that the functions Mark Oates use are currently implemented not to require Allegro to be initialized (a fact that should not be relied upon). al_map_rgb requires Allegro to be initialized, and there's no way around it.
No, it is not. As I said, it just so happens that the functions Mark Oates use are current implemented not to require Allegro to be initialize (a fact that should not be relied upon). al_map_rgb requires Allegro to be initialized, and there's no way around it.
So, what is recommended? Do I just redeclare the variable for white with this al_map_rgb(0,0,0) function in each file i need it in ?
.... just so happens that the functions Mark Oates use are currently implemented not to require Allegro to be initialized...
mwahahaa mWAAHAHAHAHAH!!
So, what is recommended? Do I just redeclare the variable for white with this al_map_rgb(0,0,0) function in each file i need it in ?
Either that or reread my post
Either that or reread my post
k got it