<-- Back to AG_Intro.3


#include <agar/core.h>
#include <agar/gui.h>


Many functions in Agar accept AG_Color parameters. This structure describes a color in terms of its red, green and blue and alpha components:
typedef struct ag_color {
	Uint8 r, g, b, a;
} AG_Color;

The alpha component may or may not be used in a particular context; a value of 0 is fully transparent and 255 is fully opaque.


AG_Color AG_ColorRGB (Uint8 r, Uint8 g, Uint8 b)

AG_Color AG_ColorRGBA (Uint8 r, Uint8 g, Uint8 b, Uint8 a)

void AG_HSV2Color (float hue, float sat, float val, AG_Color *C)

void AG_Color2HSV (const AG_Color *C, float *hue, float *sat, float *val)

AG_Color AG_ColorHex (Uint32 hex)

AG_Color AG_ColorFromString (const char *spec, const AG_Color *parentColor)

int AG_ColorCompare (AG_Color a, AG_Color b)

The AG_ColorRGB() routine returns an AG_Color from the given red, green and blue components. The alpha component is initialized to 255 (opaque).

AG_ColorRGBA() accepts an explicit alpha component.

AG_HSV2Color() maps a color in HSV space to the closest approximation in RGB space, and copies the A component as-is. The inverse operation is performed by AG_Color2HSV(). Note: H and V become increasingly lossy as S->0.

AG_ColorHex() returns an AG_Color structure from an argument of the form 0xRRGGBBAA.

The AG_ColorFromString() function converts a text-based color representation to an AG_Color. The following formats are allowed:

If components are given with a terminating "%" character, they are interpreted as a percentage of the corresponding component in parentColor (assuming the argument is non-NULL).

The AG_ColorCompare() function returns non-zero if the two given colors differ.


AG_Intro(3), AG_MapColorRGB(3), AG_MapColorRGBA(3), AG_MapPixelRGB(3), AG_MapPixelRGBA(3), AG_Widget(3)


Colors in Agar were originally described as 32-bit packed pixel values. This was replaced by the AG_Color structure in Agar 1.4.