hextoscolor

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
thenewkgb
Posts: 59
Joined: Thu Jan 25, 2024 6:54 pm
Location: UK

hextoscolor

Post 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.
Last edited by thenewkgb on Wed Feb 14, 2024 10:56 am, edited 2 times in total.
thenewkgb
Posts: 59
Joined: Thu Jan 25, 2024 6:54 pm
Location: UK

Re: hextoscolor

Post 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?
thenewkgb
Posts: 59
Joined: Thu Jan 25, 2024 6:54 pm
Location: UK

Re: hextoscolor

Post 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"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: hextoscolor

Post by CuteAlien »

Yes, only materials care about alpha.
ctoul16 returns 0xffffffff for error case, so you could check that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply