Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Hexadecimal colour codes?  (Read 7602 times)

0 Members and 2 Guests are viewing this topic.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Hexadecimal colour codes?
« on: September 19, 2015, 10:38:36 pm »
Hello

I was wondering if there's a way to use hexadecimal colour codes in the sf::Color class.
E.g: #000000 = black, instead of using words or the RGB-system.

Any way to do this?

Thanks for reading,
Niely

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Hexadecimal colour codes?
« Reply #1 on: September 19, 2015, 10:43:06 pm »
Yes:
sf::Color black(0x00000000);

Supported since 2.3.
« Last Edit: September 19, 2015, 10:44:38 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Hexadecimal colour codes?
« Reply #2 on: September 19, 2015, 11:56:19 pm »
Thanks! Working like a charm.

But I'm just wondering, why do I need to enter 8 characters (two extra zeros) instead of 6?
It's no problem, but I'm just wondering. Does C++ just works otherwise then HTML/CSS? Or is it the platform (Windows, browsers)?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Hexadecimal colour codes?
« Reply #3 on: September 20, 2015, 12:05:54 am »
Because we use RGBA (Red, Green, Blue, Alpha) for colors and HTML/CSS just uses RGB for hexadecimal values.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Hexadecimal colour codes?
« Reply #4 on: September 20, 2015, 12:15:39 am »
Okay. Good to know. Didn't knew that.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Hexadecimal colour codes?
« Reply #5 on: September 20, 2015, 10:11:27 pm »
Just a minor correction...
0x00000000 would be the equivalent of sf::Color::Transparent since the alpha is zero.

Black would be:
sf::Color black(0x000000ff); // 0xRRGGBBAA
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything