Page 1 of 1

hextoscolor

Posted: Tue Feb 13, 2024 11:20 pm
by thenewkgb
I spent about an hour coding this because I couldn't see any snippets like it. Upon checking again I saw SColor can be constructed with 0x hex values anyway. SColor must handle this better than I can.

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;
}
I didn't finish this off for both 6 and 8 inputs. One problem I found was entering "AABB;;" by accident. ctoul16 should ignore the semicolon but doesn't. This calculation gives a value of about 600 billion.

Why would ctoul16 return a u32 if the value can only return 255 max? Neither can ctoul16 handle a string.

Re: hextoscolor

Posted: Tue Feb 13, 2024 11:39 pm
by thenewkgb
I tried to see if a light could be darker.

irr::video::SColor(0x000000ff) doesn't affect the brightness

irr::video::SColor(10.f, 0.f, 0.f, 255.f) is bright blue

Do lights not care about alpha?

Re: hextoscolor

Posted: Wed Feb 14, 2024 10:51 am
by thenewkgb
One of my observations during my Half-Life/Hammer development time was finding the light color that Valve used for outdoor lighting. I came up with one solution easily remembered but slightly immature:

color = irr::video::SColor(0xFAECE5)

Faeces definition - "waste matter remaining after food has been digested, discharged from the bowels; excrement"

Re: hextoscolor

Posted: Wed Feb 14, 2024 10:58 am
by CuteAlien
Yes, only materials care about alpha.
ctoul16 returns 0xffffffff for error case, so you could check that.