MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
Public Member Functions | Static Public Member Functions | List of all members
mingfx::Color Class Reference

Detailed Description

Represents a 4-component (R,G,B,A) color, stored internally in a float array to be compatable with OpenGL.

Example usage:

Color black(0, 0, 0);
Color white(1, 1, 1);
Color gray(0.5, 0.5, 0.5);
Color tranparent_red(1.0, 0.0, 0.0, 0.5);
Color orange(1.0, 0.65, 0.0);
float red_component_of_orange = orange[0];
float green_component_of_orange = orange[1];
float blue_component_of_orange = orange[2];
float alpha_component_of_orange = orange[3];
// Use value_ptr() to send the array of floats directly to OpenGL commands
glColor4fv(orange.value_ptr());
Color()
Defaults to black.

Definition at line 41 of file color.h.

#include <color.h>

Public Member Functions

 Color ()
 Defaults to black. More...
 
 Color (float red, float green, float blue, float alpha=1.0)
 Constructs a color. Alpha defaults to 1.0 (completely opaque) More...
 
 Color (float *p)
 Constructs a point given a pointer to float array. More...
 
 Color (const std::vector< float > &vals)
 Constructs a point given a 3 or 4-element vector of floats. More...
 
 Color (const Color &p)
 Copy constructor. More...
 
virtual ~Color ()
 Color destructor. More...
 
bool operator== (const Color &p) const
 Check for equality. More...
 
bool operator!= (const Color &p) const
 Check for inequality. More...
 
Coloroperator= (const Color &p)
 Assignment operator. More...
 
float operator[] (const int i) const
 Accesses the ith component of the color, stored in RGBA order. More...
 
float & operator[] (const int i)
 Accesses the ith coordinate of the color, stored in RGBA order. More...
 
const float * value_ptr () const
 Returns a const pointer to the raw data array. More...
 
std::vector< float > ToVector () const
 
Color Lerp (const Color &b, float alpha) const
 Linear interpolation between this color and another. Alpha=0.0 returns this color, and alpha=1.0 returns the other color, other values blend between the two via a linear interpolation on each color channel. More...
 

Static Public Member Functions

static Color Lerp (const Color &a, const Color &b, float alpha)
 Linear interpolation between two colors. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b', other values blend between the two via a linear interpolation on each color channel. More...
 

Constructor & Destructor Documentation

◆ Color() [1/5]

mingfx::Color::Color ( )

Defaults to black.

◆ Color() [2/5]

mingfx::Color::Color ( float  red,
float  green,
float  blue,
float  alpha = 1.0 
)

Constructs a color. Alpha defaults to 1.0 (completely opaque)

◆ Color() [3/5]

mingfx::Color::Color ( float *  p)

Constructs a point given a pointer to float array.

◆ Color() [4/5]

mingfx::Color::Color ( const std::vector< float > &  vals)

Constructs a point given a 3 or 4-element vector of floats.

◆ Color() [5/5]

mingfx::Color::Color ( const Color p)

Copy constructor.

◆ ~Color()

virtual mingfx::Color::~Color ( )
virtual

Color destructor.

Member Function Documentation

◆ Lerp() [1/2]

static Color mingfx::Color::Lerp ( const Color a,
const Color b,
float  alpha 
)
static

Linear interpolation between two colors. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b', other values blend between the two via a linear interpolation on each color channel.

◆ Lerp() [2/2]

Color mingfx::Color::Lerp ( const Color b,
float  alpha 
) const

Linear interpolation between this color and another. Alpha=0.0 returns this color, and alpha=1.0 returns the other color, other values blend between the two via a linear interpolation on each color channel.

◆ operator!=()

bool mingfx::Color::operator!= ( const Color p) const

Check for inequality.

◆ operator=()

Color& mingfx::Color::operator= ( const Color p)

Assignment operator.

◆ operator==()

bool mingfx::Color::operator== ( const Color p) const

Check for equality.

◆ operator[]() [1/2]

float& mingfx::Color::operator[] ( const int  i)

Accesses the ith coordinate of the color, stored in RGBA order.

◆ operator[]() [2/2]

float mingfx::Color::operator[] ( const int  i) const

Accesses the ith component of the color, stored in RGBA order.

◆ ToVector()

std::vector<float> mingfx::Color::ToVector ( ) const

◆ value_ptr()

const float* mingfx::Color::value_ptr ( ) const

Returns a const pointer to the raw data array.


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