Implement Color3::FromHex()

This commit is contained in:
2024-08-02 10:49:00 -04:00
parent 0b7af6fd31
commit ff4d014739
2 changed files with 11 additions and 0 deletions

View File

@@ -16,4 +16,10 @@ namespace JGL
float Color3::GreenChannelNormalized() const { return static_cast<float>(g) / 255.f;}
Color3::Color3(u8 R, u8 G, u8 B) : r(R), g(G), b(B) {}
Color3 Color3::FromHex(const std::string &hexCode) {
u8 r, g, b;
std::sscanf(hexCode.c_str(), "#%02x%02x%02x", &r, &g, &b);
return {r, g, b};
}
}

View File

@@ -24,4 +24,9 @@ namespace JGL
float Color4::BlueChannelNormalized() const {return static_cast<float>(b/255.f); }
float Color4::AlphaChannelNormalized() const {return static_cast<float>(a/255.f); }
JGL::Color4 JGL::Color4::FromHex(const std::string &hexCode, u8 alpha) {
u8 r, g, b;
std::sscanf(hexCode.c_str(), "#%02x%02x%02x", &r, &g, &b);
return {r, g, b, alpha};
}
}