Code: Select all
irr::video::SColor hextoscolor(std::string s)
{
irr::video::SColor final_color;
irr::u32 r;
irr::u32 g;
irr::u32 b;
if(s.length() < 6 || s.length() == 7 || s.length() > 8)
return final_color = irr::video::SColor(255.f, 255.f, 255.f, 255.f);
if(s.length() == 6)
{
r = irr::core::ctoul16(s[0]) * 16 + irr::core::ctoul16(s[1]);
g = irr::core::ctoul16(s[2]) * 16 + irr::core::ctoul16(s[3]);
b = irr::core::ctoul16(s[4]) * 16 + irr::core::ctoul16(s[5]);
final_color = irr::video::SColor(255.f, r, g, b);
}
return final_color;
}
Why would ctoul16 return a u32 if the value can only return 255 max? Neither can ctoul16 handle a string.