CUGL 2.0
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Color4f Class Reference

#include <CUColor4.h>

Public Member Functions

 Color4f ()
 
 Color4f (float r, float g, float b, float a=1)
 
 Color4f (GLuint color)
 
 Color4f (const float *array)
 
 ~Color4f ()
 
Color4foperator= (unsigned int color)
 
Color4foperator= (const float *array)
 
Color4fset (float r, float g, float b, float a=1)
 
Color4fset (const float *array)
 
Color4fset (GLuint color)
 
Color4fset (const Color4f c)
 
Color4fclamp (const Color4f min, const Color4f max)
 
Color4f getClamp (const Color4f min, const Color4f max) const
 
Color4fadd (const Color4f c, bool alpha=false)
 
Color4fadd (float r, float g, float b, float a=0)
 
Color4fsubtract (const Color4f c, bool alpha=false)
 
Color4fsubtract (float r, float g, float b, float a=0)
 
Color4fscale (float s, bool alpha=false)
 
Color4fscale (float sr, float sg, float sb, float sa=1)
 
Color4fscale (const Color4f c, bool alpha=false)
 
Color4fmap (std::function< float(float)> func, bool alpha=false)
 
Color4f getMap (std::function< float(float)> func, bool alpha=false) const
 
Color4fcomplement (bool alpha=false)
 
Color4f getComplement (bool alpha=false) const
 
Color4flerp (const Color4f other, float alpha)
 
Color4fblend (const Color4f other)
 
Color4fblendPre (const Color4f other)
 
Color4fpremultiply ()
 
Color4funpremultiply ()
 
Color4f getLerp (const Color4f other, float alpha) const
 
Color4f getBlend (const Color4f other) const
 
Color4f getBlendPre (const Color4f other) const
 
Color4f getPremultiplied () const
 
Color4f getUnpremultiplied () const
 
GLuint getRGBA () const
 
Color4foperator+= (const Color4f c)
 
Color4foperator-= (const Color4f c)
 
Color4foperator*= (float s)
 
Color4foperator*= (const Color4f c)
 
const Color4f operator+ (const Color4f c) const
 
const Color4f operator- (const Color4f c) const
 
const Color4f operator* (float s) const
 
const Color4f operator* (const Color4f c) const
 
bool operator< (const Color4f c) const
 
bool operator<= (const Color4f c) const
 
bool operator> (const Color4f c) const
 
bool operator>= (const Color4f c) const
 
bool operator== (const Color4f c) const
 
bool operator!= (const Color4f c) const
 
bool darkerThan (const Color4f c) const
 
bool lighterThan (const Color4f c) const
 
bool equals (const Color4f color, float variance=CU_MATH_EPSILON) const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Vec4 () const
 
 Color4f (const Vec4 vector)
 
Color4foperator= (const Vec4 vector)
 
 operator Vec3 () const
 
 Color4f (const Vec3 vector)
 
Color4foperator= (const Vec3 vector)
 
 operator Color4 () const
 
 Color4f (Color4 color)
 
Color4foperator= (Color4 color)
 
float * get (float *array) const
 

Static Public Member Functions

static Color4flerp (const Color4f c1, const Color4f c2, float alpha, Color4f *dst)
 
static Color4fblend (const Color4f c1, const Color4f c2, Color4f *dst)
 
static Color4fblendPre (const Color4f c1, const Color4f c2, Color4f *dst)
 

Public Attributes

GLfloat r
 
GLfloat g
 
GLfloat b
 
GLfloat a
 

Static Public Attributes

static const Color4f CLEAR
 
static const Color4f WHITE
 
static const Color4f BLACK
 
static const Color4f YELLOW
 
static const Color4f BLUE
 
static const Color4f GREEN
 
static const Color4f RED
 
static const Color4f MAGENTA
 
static const Color4f CYAN
 
static const Color4f ORANGE
 
static const Color4f GRAY
 
static const Color4f CORNFLOWER
 
static const Color4f PAPYRUS
 

Detailed Description

This class is a RGBA color composed of 4 floats.

This is the preferred transparent color class for when you need to do a lot of calculations. However, it is not a compact storage format and is not ideal for shipping to the GPU. Used Color4 for that instead.

This class is in standard layout with fields of uniform type. This means that it is safe to reinterpret_cast objects to float arrays and Vec4. In addition, it has cast support for the latter. However, this class contains arithmetic methods to keep these casts from being necessary. In addition, all of the arithmetic operations implicitly clamp to maintain the invariants on all of the color values.

Constructor & Destructor Documentation

◆ Color4f() [1/7]

cugl::Color4f::Color4f ( )
inline

Constructs a new clear color (all zeros).

◆ Color4f() [2/7]

cugl::Color4f::Color4f ( float  r,
float  g,
float  b,
float  a = 1 
)

Constructs a new color initialized to the specified values.

The color values must all be in the range 0..1.

Parameters
rThe red color.
gThe green color.
bThe blue color.
aThe alpha value (optional).

◆ Color4f() [3/7]

cugl::Color4f::Color4f ( GLuint  color)

Creates a new color from an integer interpreted as an RGBA value.

This constructor processes the integer in RGBA order. Hence, 0xff0000ff represents red or the color (1, 0, 0, 1).

Parameters
colorThe integer to interpret as an RGBA value.

◆ Color4f() [4/7]

cugl::Color4f::Color4f ( const float *  array)

Constructs a new color from the values in the specified array.

The color values must all be in the range 0..1.

Parameters
arrayAn array containing the color values in the order r, g, b, a.

◆ ~Color4f()

cugl::Color4f::~Color4f ( )
inline

Destroys this color, releasing all resources

◆ Color4f() [5/7]

cugl::Color4f::Color4f ( const Vec4  vector)
explicit

Creates a color from the given vector.

The attributes are read in the order x,y,z,w.

Parameters
vectorThe vector to convert

◆ Color4f() [6/7]

cugl::Color4f::Color4f ( const Vec3  vector)
explicit

Creates a color from the given vector.

The attributes are read in the order x,y,z. The alpha value is 1.

Parameters
vectorThe vector to convert

◆ Color4f() [7/7]

cugl::Color4f::Color4f ( Color4  color)
explicit

Creates a float-based color from the given byte-based color.

The attributes are read in the order r,g,b,a. They are all divided by 255.0f before assignment.

Parameters
colorThe color to convert

Member Function Documentation

◆ add() [1/2]

Color4f& cugl::Color4f::add ( const Color4f  c,
bool  alpha = false 
)
inline

Adds the given color to this one in place.

This operation is functionally identical to additive blending. The addition is clamped so that this remains a valid color.

Parameters
cThe color to add
alphaWhether to add the alpha values (optional)
Returns
A reference to this (modified) Color4f for chaining.

◆ add() [2/2]

Color4f& cugl::Color4f::add ( float  r,
float  g,
float  b,
float  a = 0 
)
inline

Adds the given values to this color.

The addition is clamped so that this remains a valid color.

Parameters
rThe red color to add.
gThe green color to add.
bThe blue color to add.
aThe alpha value (optional).
Returns
A reference to this (modified) Color4f for chaining.

◆ blend() [1/2]

static Color4f* cugl::Color4f::blend ( const Color4f  c1,
const Color4f  c2,
Color4f dst 
)
static

Blends the two colors c1 and c2, assuming they are not premultiplied.

The blending is the standard over operation with color c1 as the source and c2 as the destination. It assumes that the color values are not premultiplied.

Parameters
c1The source color.
c2The destination color.
dstThe color to store the result in
Returns
A reference to dst for chaining

◆ blend() [2/2]

Color4f& cugl::Color4f::blend ( const Color4f  other)
inline

Blends this color with the other one, storing the new value in place.

The blending is the standard over operation with this color as the destination. It assumes that the color values are not premultiplied.

Parameters
otherThe color to interpolate with.
Returns
This color, after the blending.

◆ blendPre() [1/2]

static Color4f* cugl::Color4f::blendPre ( const Color4f  c1,
const Color4f  c2,
Color4f dst 
)
static

Blends the two colors c1 and c2, assuming they are premultiplied.

The blending is the standard over operation with color c1 as the source and c2 as the destination. It assumes that the color values are premultiplied.

Parameters
c1The source color.
c2The destination color.
dstThe color to store the result in
Returns
A reference to dst for chaining

◆ blendPre() [2/2]

Color4f& cugl::Color4f::blendPre ( const Color4f  other)
inline

Blends this color with the other one, storing the new value in place.

The blending is the standard over operation with this color as the destination. It assumes that this color is premultiplied.

Parameters
otherThe color to interpolate with.
Returns
This color, after the blending.

◆ clamp()

Color4f& cugl::Color4f::clamp ( const Color4f  min,
const Color4f  max 
)

Clamps this color within the given range.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A reference to this (modified) Color4f for chaining.

◆ complement()

Color4f& cugl::Color4f::complement ( bool  alpha = false)
inline

Complements this color.

The complement of the color is the (1-v) for each value v.

Parameters
alphaWhether to complement the alpha value (optional)
Returns
A reference to this (modified) Color4f for chaining.

◆ darkerThan()

bool cugl::Color4f::darkerThan ( const Color4f  c) const
inline

Returns true if this color is dominated by the given color.

Domination means that all components of the given color are greater than or equal to the components of this one. However, alpha is reversed for this computation, as a greater value means more opaque (and hence darker).

Parameters
cThe color to compare against.
Returns
True if this color is dominated by the given color.

◆ equals()

bool cugl::Color4f::equals ( const Color4f  color,
float  variance = CU_MATH_EPSILON 
) const
inline

Returns true if the color are within tolerance of each other.

The tolerance bounds each color attribute separately.

Parameters
colorThe color to compare against.
varianceThe comparison tolerance.
Returns
true if the color are within tolerance of each other.

◆ get()

float* cugl::Color4f::get ( float *  array) const

Writes the color values into a float array.

The attributes are read into the array in the order r,g,b,a. All values are between 0 and 1.

Parameters
arrayThe array to store the color values.
Returns
A reference to the array for chaining.

◆ getBlend()

Color4f cugl::Color4f::getBlend ( const Color4f  other) const
inline

Returns a blend of this color with the other one.

The blending is the standard over operation with this color as the destination. It assumes that the color values are not premultiplied.

Note: this does not modify this color.

Parameters
otherThe color to interpolate with.
Returns
The newly blended color

◆ getBlendPre()

Color4f cugl::Color4f::getBlendPre ( const Color4f  other) const
inline

Returns a blend of this color with the other one.

The blending is the standard over operation with this color as the destination. It assumes that this color is premultiplied.

Note: this does not modify this color.

Parameters
otherThe color to interpolate with.
Returns
The newly blended color

◆ getClamp()

Color4f cugl::Color4f::getClamp ( const Color4f  min,
const Color4f  max 
) const
inline

Returns a copy of this color clamped within the given range.

Note: this does not modify this color.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A copy of this color clamped within the given range.

◆ getComplement()

Color4f cugl::Color4f::getComplement ( bool  alpha = false) const
inline

Returns the complement of this color.

The complement of the color is the (1-v) for each value v.

Parameters
alphaWhether to complement the alpha value (optional)

Note: this does not modify this color.

Returns
The complement of this color

◆ getLerp()

Color4f cugl::Color4f::getLerp ( const Color4f  other,
float  alpha 
) const
inline

Returns the linear interpolation of this color with other.

If alpha is 0, the color is unchanged. If alpha is 1, the color is other. Otherwise it is a value in between. If alpha is outside of the range 0 to 1, it is clamped to the nearest value.

This method just implements standard linear interpolation. It does not attempt to give any blending semantics to it.

Note: this does not modify this color.

Parameters
otherThe color to interpolate with.
alphaThe interpolation value in 0..1
Returns
The linear interpolation of this color with other.

◆ getMap()

Color4f cugl::Color4f::getMap ( std::function< float(float)>  func,
bool  alpha = false 
) const
inline

Returns a copy of this color with func applied to each component.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the color values.
alphaWhether to modify the alpha value (optional)
Returns
A copy of this color with func applied to each component.

◆ getPremultiplied()

Color4f cugl::Color4f::getPremultiplied ( ) const
inline

Returns the premultiplied version of this color, using its current alpha.

This class does not store whether the color is already premultiplied. Hence premultiplying an already premultiplied color will have a compounding effect.

Note: this does not modify this color.

Returns
The newly premultiplied color

◆ getRGBA()

GLuint cugl::Color4f::getRGBA ( ) const

Returns the packed integer representation of this color

This method converts the color to a Color4 and returns the packed color of that result. This representation returned is native to the platform.

In this representation, red will always be the highest order byte and alpha will always be the lowest order byte.

Returns
the packed integer representation of this color

◆ getUnpremultiplied()

Color4f cugl::Color4f::getUnpremultiplied ( ) const
inline

Returns the unpremultiplied version of this color, using its current alpha.

This class does not store whether the color is already premultiplied. Hence unpremultiplying an non-premultiplied color will have a compounding effect.

If the alpha value is 0, the copy is equal to the original color.

Note: this does not modify this color.

Returns
The newly premultiplied color

◆ lerp() [1/2]

static Color4f* cugl::Color4f::lerp ( const Color4f  c1,
const Color4f  c2,
float  alpha,
Color4f dst 
)
static

Interpolates the two colors c1 and c2, and stores the result in dst.

If alpha is 0, the result is c1. If alpha is 1, the color is c2. Otherwise it is a value in c1..c2. If alpha is outside of the range 0 to 1, it is clamped to the nearest value.

This method just implements standard linear interpolation. It does not attempt to give any blending semantics to it.

Parameters
c1The first color.
c2The second color.
alphaThe interpolation value in 0..1
dstThe color to store the result in
Returns
A reference to dst for chaining

◆ lerp() [2/2]

Color4f& cugl::Color4f::lerp ( const Color4f  other,
float  alpha 
)
inline

Modifies this color to be the linear interpolation with other.

If alpha is 0, the color is unchanged. If alpha is 1, the color is other. Otherwise it is a value in between. If alpha is outside of the range 0 to 1, it is clamped to the nearest value.

This method just implements standard linear interpolation. It does not attempt to give any blending semantics to it.

Parameters
otherThe color to interpolate with.
alphaThe interpolation value in 0..1
Returns
This color, after the interpolation.

◆ lighterThan()

bool cugl::Color4f::lighterThan ( const Color4f  c) const
inline

Returns true if this color dominates the given color.

Domination means that all components of this color are greater than or equal to the components of the given color. However, alpha is reversed for this computation, as a lesser value means more transparent (and hence lighter).

Parameters
cThe color to compare against.
Returns
True if this color is dominated by the given color.

◆ map()

Color4f& cugl::Color4f::map ( std::function< float(float)>  func,
bool  alpha = false 
)
inline

Maps the given function to the color values in place.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h. However, the values are clamped to ensure that this remains a valid color.

Parameters
funcThe function to map on the color values.
alphaWhether to modify the alpha value (optional)
Returns
A reference to this (modified) Color4f for chaining.

◆ operator Color4()

cugl::Color4f::operator Color4 ( ) const

Cast from Color4f to a byte-based Color4.

◆ operator std::string()

cugl::Color4f::operator std::string ( ) const
inline

Cast from Color4f to a string.

◆ operator Vec3()

cugl::Color4f::operator Vec3 ( ) const

Cast from Color4f to a vector.

◆ operator Vec4()

cugl::Color4f::operator Vec4 ( ) const

Cast from Color4f to a vector.

◆ operator!=()

bool cugl::Color4f::operator!= ( const Color4f  c) const
inline

Returns true if this color is not equal to the given color.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
cThe color to compare against.
Returns
True if this color is not equal to the given color.

◆ operator*() [1/2]

const Color4f cugl::Color4f::operator* ( const Color4f  c) const
inline

Returns the scalar product of this color with the given color.

This operation is functionally identical to multiplicative blending.

Note: this does not modify this color.

Parameters
cThe color to scale by.
Returns
The scalar product of this color with the given color.

◆ operator*() [2/2]

const Color4f cugl::Color4f::operator* ( float  s) const
inline

Returns the scalar product of this color with the given color.

The scaling is clamped so that this remains a valid color.

Note: this does not modify this color.

Parameters
sThe value to scale by.
Returns
The scalar product of this color with the given value.

◆ operator*=() [1/2]

Color4f& cugl::Color4f::operator*= ( const Color4f  c)
inline

Scales this color nonuniformly by the given color.

This operation is functionally identical to multiplicative blending.

Parameters
cThe color to scale by
Returns
A reference to this (modified) Color4f for chaining.

◆ operator*=() [2/2]

Color4f& cugl::Color4f::operator*= ( float  s)
inline

Scales this color in place by the given factor.

The scaling is clamped so that this remains a valid color.

This version of scaling always multiplies the alpha values.

Parameters
sThe value to scale by
Returns
A reference to this (modified) Color4f for chaining.

◆ operator+()

const Color4f cugl::Color4f::operator+ ( const Color4f  c) const
inline

Returns the sum of this color with the given color.

This operation is functionally identical to additive blending. The addition is clamped so that this remains a valid color.

This version of addition always adds alpha values.

Note: this does not modify this color.

Parameters
cThe color to add.
Returns
The sum of this color with the given color.

◆ operator+=()

Color4f& cugl::Color4f::operator+= ( const Color4f  c)
inline

Adds the given color to this one in place.

This operation is functionally identical to additive blending. The addition is clamped so that this remains a valid color.

This version of addition always adds alpha values.

Parameters
cThe color to add
Returns
A reference to this (modified) Color4f for chaining.

◆ operator-()

const Color4f cugl::Color4f::operator- ( const Color4f  c) const
inline

Returns the difference of this color with the given color.

This operation is functionally identical to subtractive blending. The subtraction is clamped so that this remains a valid color.

This version of subtraction always adds subtracts values.

Note: this does not modify this color.

Parameters
cThe color to subtract.
Returns
The difference of this color with the given color.

◆ operator-=()

Color4f& cugl::Color4f::operator-= ( const Color4f  c)
inline

Subtracts the given color from this one in place.

This operation is functionally identical to subtractive blending. The subtraction is clamped so that this remains a valid color.

This version of subtraction always subtracts alpha values.

Parameters
cThe color to subtract
Returns
A reference to this (modified) Color4f for chaining.

◆ operator<()

bool cugl::Color4f::operator< ( const Color4f  c) const

Returns true if this color is less than the given color.

This comparison uses lexicographical order of rgba. To test if all components in this color are less than those of c, use the method darkerThan().

Parameters
cThe color to compare against.
Returns
True if this color is less than the given color.

◆ operator<=()

bool cugl::Color4f::operator<= ( const Color4f  c) const
inline

Returns true if this color is less than or equal the given color.

This comparison uses lexicographical order of rgba. To test if all components in this color are less than those of c, use the method darkerThan().

Parameters
cThe color to compare against.
Returns
True if this color is less than or equal the given color.

◆ operator=() [1/5]

Color4f& cugl::Color4f::operator= ( Color4  color)

Sets the attributes of this color from the given byte-based color.

The attributes are read in the order r,g,b,a. They are all divided by 255.0f before assignment.

Parameters
colorThe color to convert.
Returns
A reference to this (modified) Color4f for chaining.

◆ operator=() [2/5]

Color4f& cugl::Color4f::operator= ( const float *  array)
inline

Sets the elements of this color from the values in the specified array.

The color values must all be in the range 0..1.

Parameters
arrayAn array containing the color values in the order r, g, b, a.
Returns
A reference to this (modified) Color4f for chaining.

◆ operator=() [3/5]

Color4f& cugl::Color4f::operator= ( const Vec3  vector)

Sets the coordinates of this color to those of the given vector.

The attributes are read in the order x,y,z. The alpha value is 1.

Parameters
vectorThe vector to convert
Returns
A reference to this (modified) Color4f for chaining.

◆ operator=() [4/5]

Color4f& cugl::Color4f::operator= ( const Vec4  vector)

Sets the coordinates of this color to those of the given vector.

The attributes are read in the order x,y,z,w.

Parameters
vectorThe vector to convert
Returns
A reference to this (modified) Color4f for chaining.

◆ operator=() [5/5]

Color4f& cugl::Color4f::operator= ( unsigned int  color)
inline

Sets this color to an integer interpreted as an RGBA value.

This setter processes the integer in RGBA order. Hence, 0xff0000ff represents red or the color (1, 0, 0, 1).

Parameters
colorThe integer to interpret as an RGBA value.
Returns
A reference to this (modified) Color4f for chaining.

◆ operator==()

bool cugl::Color4f::operator== ( const Color4f  c) const
inline

Returns true if this color is equal to the given color.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
cThe color to compare against.
Returns
True if this color is equal to the given color.

◆ operator>()

bool cugl::Color4f::operator> ( const Color4f  c) const

Returns true if this color is greater than the given color.

This comparison uses lexicographical order of rgba. To test if all components in this color are greater than those of c, use the method lighterThan().

Parameters
cThe color to compare against.
Returns
True if this color is greater than the given color.

◆ operator>=()

bool cugl::Color4f::operator>= ( const Color4f  c) const
inline

Returns true if this color is greater than or equal the given color.

This comparison uses lexicographical order of rgba. To test if all components in this color are greater than those of c, use the method lighterThan().

Parameters
cThe color to compare against.
Returns
True if this color is greater than or equal the given color.

◆ premultiply()

Color4f& cugl::Color4f::premultiply ( )
inline

Premultiplies this color with its current alpha.

This class does not store whether the color is already premultiplied. Hence premultiplying an already premultiplied color will have a compounding effect.

Returns
This color, after premultiplication.

◆ scale() [1/3]

Color4f& cugl::Color4f::scale ( const Color4f  c,
bool  alpha = false 
)
inline

Scales this color nonuniformly by the given color.

This operation is functionally identical to multiplicative blending.

Parameters
cThe color to scale by
alphaWhether to scale the alpha value (optional)
Returns
A reference to this (modified) Color4f for chaining.

◆ scale() [2/3]

Color4f& cugl::Color4f::scale ( float  s,
bool  alpha = false 
)
inline

Scales this color in place by the given factor.

The scaling is clamped so that this remains a valid color.

Parameters
sThe scalar to multiply by
alphaWhether to scale the alpha value (optional)
Returns
A reference to this (modified) Color4f for chaining.

◆ scale() [3/3]

Color4f& cugl::Color4f::scale ( float  sr,
float  sg,
float  sb,
float  sa = 1 
)
inline

Scales this color nonuniformly by the given factors.

The scaling is clamped so that this remains a valid color.

Parameters
srThe scalar to multiply the red value
sgThe scalar to multiply the green value
sbThe scalar to multiply the blue value
saThe scalar to multiply alpha value (optional).
Returns
A reference to this (modified) Color4f for chaining.

◆ set() [1/4]

Color4f& cugl::Color4f::set ( const Color4f  c)
inline

Sets the values of this color to those in the specified color.

Parameters
cThe color to copy.
Returns
A reference to this (modified) Color4f for chaining.

◆ set() [2/4]

Color4f& cugl::Color4f::set ( const float *  array)

Sets the elements of this color from the values in the specified array.

The color values must all be in the range 0..1.

Parameters
arrayAn array containing the color values in the order r, g, b, a.
Returns
A reference to this (modified) Color4f for chaining.

◆ set() [3/4]

Color4f& cugl::Color4f::set ( float  r,
float  g,
float  b,
float  a = 1 
)

Sets the elements of this color to the specified values.

The color values must all be in the range 0..1.

Parameters
rThe red color.
gThe green color.
bThe blue color.
aThe alpha value (optional).
Returns
A reference to this (modified) Color4f for chaining.

◆ set() [4/4]

Color4f& cugl::Color4f::set ( GLuint  color)

Sets this color to an integer interpreted as an RGBA value.

This setter processes the integer in RGBA order. Hence, 0xff0000ff represents red or the color (1, 0, 0, 1).

Parameters
colorThe integer to interpret as an RGBA value.
Returns
A reference to this (modified) Color4f for chaining.

◆ subtract() [1/2]

Color4f& cugl::Color4f::subtract ( const Color4f  c,
bool  alpha = false 
)
inline

Subtracts the given color from this one in place.

This operation is functionally identical to subtractive blending. The subtraction is clamped so that this remains a valid color.

Parameters
cThe color to subtract
alphaWhether to subtract the alpha value (optional)
Returns
A reference to this (modified) Color4f for chaining.

◆ subtract() [2/2]

Color4f& cugl::Color4f::subtract ( float  r,
float  g,
float  b,
float  a = 0 
)
inline

Subtracts the given values from this color.

The subtraction is clamped so that this remains a valid color.

Parameters
rThe red color to subtract.
gThe green color to subtract.
bThe blue color to subtract.
aThe alpha value (optional).
Returns
A reference to this (modified) Color4f for chaining.

◆ toString()

std::string cugl::Color4f::toString ( bool  verbose = false) const

Returns a string representation of this vector for debuggging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this vector for debuggging purposes.

◆ unpremultiply()

Color4f& cugl::Color4f::unpremultiply ( )
inline

Undoes premultiplication this color with its current alpha.

This class does not store whether the color is already premultiplied. Hence unpremultiplying an non-premultiplied color will have a compounding effect.

If the alpha value is 0, the color is unchanged.

Returns
This color, after undoing premultiplication.

Member Data Documentation

◆ a

GLfloat cugl::Color4f::a

The alpha value

◆ b

GLfloat cugl::Color4f::b

The blue value

◆ BLACK

const Color4f cugl::Color4f::BLACK
static

The Black color (0,0,0,1)

◆ BLUE

const Color4f cugl::Color4f::BLUE
static

The Blue color (0,0,1,1)

◆ CLEAR

const Color4f cugl::Color4f::CLEAR
static

The Clear color (0,0,0,0)

◆ CORNFLOWER

const Color4f cugl::Color4f::CORNFLOWER
static

The classic XNA color (0.392,0.584,0.93,1)

◆ CYAN

const Color4f cugl::Color4f::CYAN
static

The Cyan color (0,1,1,1)

◆ g

GLfloat cugl::Color4f::g

The green value

◆ GRAY

const Color4f cugl::Color4f::GRAY
static

The Gray color (0.65,0.65,0.65,1)

◆ GREEN

const Color4f cugl::Color4f::GREEN
static

The Green color (0,1,0,1)

◆ MAGENTA

const Color4f cugl::Color4f::MAGENTA
static

The Magenta color (1,0,1,1)

◆ ORANGE

const Color4f cugl::Color4f::ORANGE
static

The Orange color (1,0.5,0,1)

◆ PAPYRUS

const Color4f cugl::Color4f::PAPYRUS
static

The Playing Fields color (0.933f,0.99f,0.65f,1.0f)

◆ r

GLfloat cugl::Color4f::r

The red value

◆ RED

const Color4f cugl::Color4f::RED
static

The Red color (1,0,0,1)

◆ WHITE

const Color4f cugl::Color4f::WHITE
static

The White color (1,1,1,1)

◆ YELLOW

const Color4f cugl::Color4f::YELLOW
static

The Yellow color (1,1,0,1)


The documentation for this class was generated from the following file: