Question

I already learnt the working mechanis of RGBA, so I realised that hexadecimal numbers that belongs to the different colours can be turned into simple integers. It means that I can store colours in integers, even though some of them are quite big.

My question is that how can I get the colour that belongs to an integer I give to the program?

EDIT: of course I forgot to mention that I use Allegro too but I'm new in it...are there any functions of whatever that can do it?

Was it helpful?

Solution

It sounds like you are using Allegro 4 if you are storing colors as integers. It provides a variety of functions for you to use, just check out the manual.

// int makecol(int r, int g, int b);

int white = makecol(255, 255, 255);
int green = makecol(0, 255, 0);

Or the inverse:

int r = getr(color);
int g = getg(color);
int b = getb(color);

With Allegro 4, the ordering depends on the graphics card. So the return value of makecol() can be different for the same color depending if it is stored RGB or BGR. So you must use the above functions to get the proper color values, and only after setting the graphics mode.

If using Allegro 5 (which I highly recommend over Allegro 4), you use the ALLEGRO_COLOR struct, which hides the underlying implementation details and thus none of the above is applicable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top