Game Development Reference
In-Depth Information
In our case we need to do a bitwise OR operation on all the shifted channels, to store the
final result in a single 32bit value.
unsigned int color = (alpha << 24) | (red << 16) | (green << 8) | blue;
To make our color class intuitive to use, we will provide a type operator that will perform
the conversion from floating point representation to a 32-bit value.
class color
{
public:
color::operator const unsigned int() const;
enum { R, G, B, A };
private:
float m_color[4];
};
inline color::operator const unsigned int() const
{
auto red = static_cast<unsigned char>(m_color[R] * 255.f);
auto green = static_cast<unsigned char>(m_color[G] * 255.f);
auto blue = static_cast<unsigned char>(m_color[B] * 255.f);
auto alpha = static_cast<unsigned char>(m_color[A] * 255.f);
return (a << 24) | (r << 16) | (g << 8) | b;
}
Search WWH ::




Custom Search