|
ALLEGRO_COLOR for noobs |
kingnoob
Member #18,984
January 2021
|
I'm new to Allegro. And I had a hard time figuring out how to make and array of ALLEGRO_COLOR structures. I figured it out in probably a very noobish way. Here it is but maybe someone will show how it can be done better, idk. First define the colors. #define BLACK al_map_rgb(0, 0 ,0) Then create the global ALLEGRO_COLOR structure array. struct ALLEGRO_COLOR color[MAX_COLORS]; Then in Initialize() after al_init(). struct ALLEGRO_COLOR c[] = And now one can use the global array as in color[i] or just use a color define as in RED wherever an ALLEGRO_COLOR is needed. |
amarillion
Member #940
January 2001
|
Isn't that redundant? Why don't you define the array directly like so: struct ALLEGRO_COLOR color[] = { BLACK,DARKBLUE,DARKRED,DARKGREEN,PINK,YELLOW,ORANGE,PURPLE,BLUE,RED,GREEN,BEIGE,BROWN }; No need to copy the data. -- |
Peter Hull
Member #1,136
March 2001
|
amarillion said: Why don't you You can't call al_map_rgb before al_init so it doesn't work as a global initialiser. (actually the reason why you can't is a bit disappointing and could be fixed quite easily I think)
|
Chris Katko
Member #1,881
January 2002
|
Peter Hull said: (actually the reason why you can't is a bit disappointing and could be fixed quite easily I think) I thought it was because the color format could change based on what system you're on. -----sig: |
SiegeLord
Member #7,827
October 2006
|
Peter Hull said: (actually the reason why you can't is a bit disappointing and could be fixed quite easily I think) "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Peter Hull
Member #1,136
March 2001
|
Nice one SL! Chris Katko said: I thought it was because the color format could change based on what system you're on. So did I until recently; I was probably thinking of makecol from Allegro 4. ALLEGRO_COLOR is just a 16-byte struct of four floats R, G, B and A. al_map_rgb converts each integer 0..255 to a float using a lookup table and it's that table that needs to be initialised by al_init (that is, until PR #1217!)
|
Elias
Member #358
May 2000
|
I think even the color addon will work with this change, so al_color_name("red") should be callable before main as well now (and without initializing the color addon). Not sure there's much reason to advertise it in the documentation but I may start doing it from now on in some test code -- |
|