V-ART
Public Member Functions | Static Public Member Functions | Friends | List of all members
VART::Color Class Reference

RGBA color representation. More...

#include <color.h>

Public Member Functions

 Color ()
 Creates a black, opaque color. More...
 
 Color (const Color &color)
 
 Color (unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
 
void SetR (unsigned char r)
 
void SetG (unsigned char g)
 
void SetB (unsigned char b)
 
void SetA (unsigned char a)
 
void SetRGBA (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 
unsigned char GetR () const
 
unsigned char GetG () const
 
unsigned char GetB () const
 
unsigned char GetA () const
 
void GetRGBA (unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) const
 
void Get (float rgbaVec[4]) const
 Returns RGBA componts as a vector of floats. More...
 
Coloroperator= (const Color &color)
 
Color operator+ (const Color &color) const
 
Color operator- (const Color &color) const
 
bool operator== (const Color &color) const
 
bool operator!= (const Color &color) const
 
void GetScaled (float escalar, float result[4]) const
 Multiplies RGB components, keeps A component. More...
 
void GetScaled (float escalar, Color *result) const
 Multiplies RGB components, keeps A component. More...
 

Static Public Member Functions

static Color HSV (unsigned char h_, unsigned char s_, unsigned char v_)
 HSV named Constructor. More...
 
static const ColorBLACK ()
 Black opaque color. More...
 
static const ColorRED ()
 Red opaque color. More...
 
static const ColorGREEN ()
 Green opaque color. More...
 
static const ColorBLUE ()
 Blue opaque color. More...
 
static const ColorMAGENTA ()
 Magenta opaque color. More...
 
static const ColorCYAN ()
 Cyan opaque color. More...
 
static const ColorYELLOW ()
 Yellow opaque color. More...
 
static const ColorWHITE ()
 White opaque color. More...
 
static Color RANDOM ()
 Returns a randomly chosen color. More...
 

Friends

std::ostream & operator<< (std::ostream &output, const Color &c)
 

Detailed Description

RGBA color representation.

Colors are quadruplets of Red (R), Green (G), Blue (B) and Alpha (A) components where A is the opacity of a color. Note that OpenGL requires that blending is enabled in order to make actual use of the alpha value - this is NOT done automatically by V-ART to produce faster drawings when blending is not needed. To enable blending the programmer should do it in the application's main routine, with code like "glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);". Enabling blending may not be enough in some cases: OpenGL uses traditional frame-buffer pixel blending which requires that farther fragments be drawn first in order to achieve correct blending results. In other words, translucent objects may appear opaque if drawn before the objects behind them.

Definition at line 24 of file color.h.

Constructor & Destructor Documentation

VART::Color::Color ( )

Creates a black, opaque color.

Definition at line 15 of file color.cpp.

VART::Color::Color ( const Color color)

Definition at line 30 of file color.cpp.

VART::Color::Color ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a = 255 
)

Definition at line 22 of file color.cpp.

Member Function Documentation

const VART::Color & VART::Color::BLACK ( )
static

Black opaque color.

Definition at line 70 of file color.cpp.

Referenced by VART::Material::PLASTIC_BLACK(), and VART::MeshObject::ReadMaterialTable().

const VART::Color & VART::Color::BLUE ( )
static

Blue opaque color.

Definition at line 85 of file color.cpp.

Referenced by VART::Material::PLASTIC_BLUE().

const VART::Color & VART::Color::CYAN ( )
static

Cyan opaque color.

Definition at line 95 of file color.cpp.

void VART::Color::Get ( float  rgbaVec[4]) const

Returns RGBA componts as a vector of floats.

Definition at line 138 of file color.cpp.

unsigned char VART::Color::GetA ( ) const
inline

Definition at line 39 of file color.h.

unsigned char VART::Color::GetB ( ) const
inline

Definition at line 38 of file color.h.

unsigned char VART::Color::GetG ( ) const
inline

Definition at line 37 of file color.h.

unsigned char VART::Color::GetR ( ) const
inline

Definition at line 36 of file color.h.

void VART::Color::GetRGBA ( unsigned char *  r,
unsigned char *  g,
unsigned char *  b,
unsigned char *  a 
) const

Definition at line 130 of file color.cpp.

void VART::Color::GetScaled ( float  escalar,
float  result[4] 
) const

Multiplies RGB components, keeps A component.

Use this method to make a color darker, by multipling it by a number in the range 0..1.

Parameters
escalar[in] Number to multiply against RGB components. Should be in the range 0..1 in order to garantee that the result is in the range 0..1. No checking on the range is done.
result[out] Result of multiplication as RGBA float vector. Components should be in the range 0..1, but no clamping is done.

Definition at line 178 of file color.cpp.

Referenced by VART::Material::Material(), and VART::Material::SetPlasticColor().

void VART::Color::GetScaled ( float  escalar,
VART::Color result 
) const

Multiplies RGB components, keeps A component.

Use this method to make a color darker, by multipling it by a number in the range 0..1.

Parameters
escalar[in] Number to multiply against RGB components. Should be in the range 0..1 in order to garantee that the result is in the range 0..1. No checking on the range is done.
result[out] Result of multiplication as Color. Components should be in the range 0..1, but no clamping is done.

Definition at line 187 of file color.cpp.

const VART::Color & VART::Color::GREEN ( )
static

Green opaque color.

Definition at line 80 of file color.cpp.

Referenced by VART::Material::PLASTIC_GREEN().

VART::Color VART::Color::HSV ( unsigned char  h_,
unsigned char  s_,
unsigned char  v_ 
)
static

HSV named Constructor.

Definition at line 37 of file color.cpp.

const VART::Color & VART::Color::MAGENTA ( )
static

Magenta opaque color.

Definition at line 90 of file color.cpp.

bool VART::Color::operator!= ( const Color color) const

Definition at line 171 of file color.cpp.

VART::Color VART::Color::operator+ ( const Color color) const

Definition at line 152 of file color.cpp.

VART::Color VART::Color::operator- ( const Color color) const

Definition at line 158 of file color.cpp.

VART::Color & VART::Color::operator= ( const Color color)

Definition at line 144 of file color.cpp.

bool VART::Color::operator== ( const Color color) const

Definition at line 164 of file color.cpp.

VART::Color VART::Color::RANDOM ( )
static

Returns a randomly chosen color.

You may want to initialize the random number generator with something like: srand(static_cast<unsigned int>(time(NULL))) before generating random colors.

Definition at line 110 of file color.cpp.

References SetA(), SetB(), SetG(), and SetR().

const VART::Color & VART::Color::RED ( )
static

Red opaque color.

Definition at line 75 of file color.cpp.

Referenced by VART::BoundingBox::BoundingBox(), and VART::Material::PLASTIC_RED().

void VART::Color::SetA ( unsigned char  a)
inline

Definition at line 34 of file color.h.

Referenced by RANDOM().

void VART::Color::SetB ( unsigned char  b)
inline

Definition at line 33 of file color.h.

Referenced by RANDOM().

void VART::Color::SetG ( unsigned char  g)
inline

Definition at line 32 of file color.h.

Referenced by RANDOM().

void VART::Color::SetR ( unsigned char  r)
inline

Definition at line 31 of file color.h.

Referenced by RANDOM().

void VART::Color::SetRGBA ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

Definition at line 123 of file color.cpp.

const VART::Color & VART::Color::WHITE ( )
static

White opaque color.

Definition at line 105 of file color.cpp.

Referenced by VART::Light::BRIGHT_AMBIENT(), VART::Material::PLASTIC_WHITE(), VART::Scene::Scene(), and VART::Light::SUN().

const VART::Color & VART::Color::YELLOW ( )
static

Yellow opaque color.

Definition at line 100 of file color.cpp.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  output,
const Color c 
)
friend

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