Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::video::SColor Class Reference

Class representing a 32 bit ARGB color. More...

#include <nirtcpp/core/engine/SColor.hpp>

Public Member Functions

 SColor ()
 Constructor of the Color. Does nothing.
 
 SColor (u32 a, u32 r, u32 g, u32 b)
 Constructs the color from 4 values representing the alpha, red, green and blue component.
 
 SColor (u32 clr)
 Constructs the color from a 32 bit value. Could be another color.
 
u32 getAlpha () const
 Returns the alpha component of the color.
 
u32 getRed () const
 Returns the red component of the color.
 
u32 getGreen () const
 Returns the green component of the color.
 
u32 getBlue () const
 Returns the blue component of the color.
 
f32 getLightness () const
 Get lightness of the color in the range [0,255].
 
f32 getLuminance () const
 Get luminance of the color in the range [0,255].
 
u32 getAverage () const
 Get average intensity of the color in the range [0,255].
 
void setAlpha (u32 a)
 Sets the alpha component of the Color.
 
void setRed (u32 r)
 Sets the red component of the Color.
 
void setGreen (u32 g)
 Sets the green component of the Color.
 
void setBlue (u32 b)
 Sets the blue component of the Color.
 
u16 toA1R5G5B5 () const
 Calculates a 16 bit A1R5G5B5 value of this color.
 
void toOpenGLColor (u8 *dest) const
 Converts color to OpenGL color format.
 
void set (u32 a, u32 r, u32 g, u32 b)
 Sets all four components of the color at once.
 
void set (u32 col)
 
bool operator== (const SColor &other) const
 Compares the color to another color.
 
bool operator!= (const SColor &other) const
 Compares the color to another color.
 
bool operator< (const SColor &other) const
 comparison operator
 
SColor operator+ (const SColor &other) const
 Adds two colors, result is clamped to 0..255 values.
 
SColor getInterpolated (const SColor &other, f32 d) const
 Interpolates the color with a f32 value to another color.
 
SColor getInterpolated_quadratic (const SColor &c1, const SColor &c2, f32 d) const
 Returns interpolated color. ( quadratic )
 
void setData (const void *data, ECOLOR_FORMAT format)
 set the color by expecting data in the given format
 
void getData (void *data, ECOLOR_FORMAT format) const
 Write the color to data in the defined format.
 

Public Attributes

u32 color
 color in A8R8G8B8 Format
 

Detailed Description

Class representing a 32 bit ARGB color.

The color values for alpha, red, green, and blue are stored in a single u32. So all four values may be between 0 and 255. Alpha in Nirtcpp is opacity, so 0 is fully transparent, 255 is fully opaque (solid). This class is used by most parts of the Nirtcpp Engine to specify a color. Another way is using the class SColorf, which stores the color values in 4 floats. This class must consist of only one u32 and must not use virtual functions.

Constructor & Destructor Documentation

◆ SColor() [1/2]

nirt::video::SColor::SColor ( )
inline

Constructor of the Color. Does nothing.

The color value is not initialized to save time.

◆ SColor() [2/2]

nirt::video::SColor::SColor ( u32  a,
u32  r,
u32  g,
u32  b 
)
inline

Constructs the color from 4 values representing the alpha, red, green and blue component.

Must be values between 0 and 255.

Member Function Documentation

◆ getAlpha()

u32 nirt::video::SColor::getAlpha ( ) const
inline

Returns the alpha component of the color.

The alpha component defines how opaque a color is.

Returns
The alpha value of the color. 0 is fully transparent, 255 is fully opaque.

◆ getBlue()

u32 nirt::video::SColor::getBlue ( ) const
inline

Returns the blue component of the color.

Returns
Value between 0 and 255, specifying how blue the color is. 0 means no blue, 255 means full blue.

◆ getData()

void nirt::video::SColor::getData ( void *  data,
ECOLOR_FORMAT  format 
) const
inline

Write the color to data in the defined format.

Parameters
datatarget to write the color. Must contain sufficiently large memory to receive the number of bytes neede for format
formattells the format used to write the color into data

◆ getGreen()

u32 nirt::video::SColor::getGreen ( ) const
inline

Returns the green component of the color.

Returns
Value between 0 and 255, specifying how green the color is. 0 means no green, 255 means full green.

◆ getInterpolated()

SColor nirt::video::SColor::getInterpolated ( const SColor other,
f32  d 
) const
inline

Interpolates the color with a f32 value to another color.

Parameters
otherOther color
dvalue between 0.0f and 1.0f. d=0 returns other, d=1 returns this, values between interpolate.
Returns
Interpolated color.

◆ getInterpolated_quadratic()

SColor nirt::video::SColor::getInterpolated_quadratic ( const SColor c1,
const SColor c2,
f32  d 
) const
inline

Returns interpolated color. ( quadratic )

Parameters
c1first color to interpolate with
c2second color to interpolate with
dvalue between 0.0f and 1.0f.

◆ getRed()

u32 nirt::video::SColor::getRed ( ) const
inline

Returns the red component of the color.

Returns
Value between 0 and 255, specifying how red the color is. 0 means no red, 255 means full red.

◆ operator!=()

bool nirt::video::SColor::operator!= ( const SColor other) const
inline

Compares the color to another color.

Returns
True if the colors are different, and false if they are the same.

◆ operator+()

SColor nirt::video::SColor::operator+ ( const SColor other) const
inline

Adds two colors, result is clamped to 0..255 values.

Parameters
otherColor to add to this color
Returns
Addition of the two colors, clamped to 0..255 values

◆ operator<()

bool nirt::video::SColor::operator< ( const SColor other) const
inline

comparison operator

Returns
True if this color is smaller than the other one

◆ operator==()

bool nirt::video::SColor::operator== ( const SColor other) const
inline

Compares the color to another color.

Returns
True if the colors are the same, and false if not.

◆ set()

void nirt::video::SColor::set ( u32  a,
u32  r,
u32  g,
u32  b 
)
inline

Sets all four components of the color at once.

Constructs the color from 4 values representing the alpha, red, green and blue components of the color. Must be values between 0 and 255.

Parameters
aAlpha component of the color. The alpha component defines how transparent a color should be. Has to be a value between 0 and 255. 255 means not transparent (opaque), 0 means fully transparent.
rSets the red component of the Color. Has to be a value between 0 and 255. 0 means no red, 255 means full red.
gSets the green component of the Color. Has to be a value between 0 and 255. 0 means no green, 255 means full green.
bSets the blue component of the Color. Has to be a value between 0 and 255. 0 means no blue, 255 means full blue.

◆ setAlpha()

void nirt::video::SColor::setAlpha ( u32  a)
inline

Sets the alpha component of the Color.

The alpha component defines how transparent a color should be.

Parameters
aThe alpha value of the color. 0 is fully transparent, 255 is fully opaque.

◆ setBlue()

void nirt::video::SColor::setBlue ( u32  b)
inline

Sets the blue component of the Color.

Parameters
bHas to be a value between 0 and 255. 0 means no blue, 255 means full blue.

◆ setData()

void nirt::video::SColor::setData ( const void *  data,
ECOLOR_FORMAT  format 
)
inline

set the color by expecting data in the given format

Parameters
datamust point to valid memory containing color information in the given format
formattells the format in which data is available

◆ setGreen()

void nirt::video::SColor::setGreen ( u32  g)
inline

Sets the green component of the Color.

Parameters
gHas to be a value between 0 and 255. 0 means no green, 255 means full green.

◆ setRed()

void nirt::video::SColor::setRed ( u32  r)
inline

Sets the red component of the Color.

Parameters
rHas to be a value between 0 and 255. 0 means no red, 255 means full red.

◆ toA1R5G5B5()

u16 nirt::video::SColor::toA1R5G5B5 ( ) const
inline

Calculates a 16 bit A1R5G5B5 value of this color.

Returns
16 bit A1R5G5B5 value of this color.

◆ toOpenGLColor()

void nirt::video::SColor::toOpenGLColor ( u8 dest) const
inline

Converts color to OpenGL color format.

From ARGB to RGBA in 4 byte components for endian aware passing to OpenGL

Parameters
destaddress where the 4x8 bit OpenGL color is stored.

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

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print