Added ptr() that can be passed to glColorNubv
This commit is contained in:
@@ -8,19 +8,20 @@ using u8 = uint8_t;
|
||||
/// Represents a 3-channel color value, with Red, Green and Blue components.
|
||||
class Color3 {
|
||||
public:
|
||||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
u8 r; // Red value 0-255
|
||||
u8 g; // Green value 0-255
|
||||
u8 b; // Blue value 0-255
|
||||
public:
|
||||
/// Explicitly constructs a Color3 from the given Red, Green, and Blue values.
|
||||
Color3(u8 R, u8 G, u8 B);
|
||||
/// Returns a Color3 parsed from the given hexadecimal string.
|
||||
static Color3 FromHex(const std::string& hexCode);
|
||||
static Color3 FromHSL(u8 hue, u8 saturation, u8 lightness);
|
||||
|
||||
Color3() = default;
|
||||
public:
|
||||
/// Returns a Color3 that is somewhere in-between this and the given Color3, determined by the alpha [0-1].
|
||||
Color3 Lerp(const Color3& rhs, float alpha) const;
|
||||
Color3 Lerp(const Color3& rhs, float t) const;
|
||||
|
||||
/// Returns the red channel [0-255].
|
||||
u8 RedChannel () const;
|
||||
@@ -35,4 +36,7 @@ public:
|
||||
/// Returns the blue channel normalized from [0-255] to [0-1].
|
||||
float BlueChannelNormalized() const;
|
||||
|
||||
u8* ptr();
|
||||
[[nodiscard]] const u8* ptr() const;
|
||||
|
||||
};
|
@@ -7,10 +7,8 @@
|
||||
|
||||
#include <Color3.hpp>
|
||||
|
||||
|
||||
using u8 = uint8_t;
|
||||
|
||||
|
||||
class Color4 {
|
||||
public:
|
||||
u8 r;
|
||||
@@ -23,13 +21,23 @@ public:
|
||||
Color4(u8 red, u8 green, u8 blue, u8 alpha = 255);
|
||||
static Color4 FromColor3(const Color3& color3, u8 alpha = 255);
|
||||
static Color4 FromHex(const std::string& hexCode, u8 alpha = 255);
|
||||
|
||||
static Color4 FromHSL(u8 hue, u8 saturation, u8 lightness, u8 alpha = 255);
|
||||
static Color4 FromNormalized(float red, float green, float blue, float alpha);
|
||||
public:
|
||||
|
||||
[[nodiscard]] Color4 Lerp(const Color4& rhs, float t) const;
|
||||
static Color4 Lerp(const Color4& lhs, const Color4& rhs, float t);
|
||||
|
||||
u8 RedChannel() const;
|
||||
u8 GreenChannel() const;
|
||||
u8 BlueChannel() const;
|
||||
u8 AlphaChannel() const;
|
||||
|
||||
u8 R() const { return AlphaChannel(); }
|
||||
u8 G() const { return GreenChannel(); }
|
||||
u8 B() const { return BlueChannel(); }
|
||||
u8 A() const { return AlphaChannel(); }
|
||||
|
||||
float RedChannelNormalized() const;
|
||||
float GreenChannelNormalized() const;
|
||||
float BlueChannelNormalized() const;
|
||||
@@ -38,8 +46,8 @@ public:
|
||||
[[nodiscard]] float RN() const { return RedChannelNormalized(); }
|
||||
[[nodiscard]] float GN() const { return GreenChannelNormalized(); }
|
||||
[[nodiscard]] float BN() const { return BlueChannelNormalized(); }
|
||||
[[nodiscard]] float AN() const { return AlphaChannelNormalized(); }
|
||||
|
||||
|
||||
int* ptr() { return reinterpret_cast<int *>(&r);}
|
||||
[[nodiscard]] const int* ptr() const { return reinterpret_cast<const int *>(&r);}
|
||||
u8* ptr();
|
||||
[[nodiscard]] const u8* ptr() const;
|
||||
};
|
Reference in New Issue
Block a user