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

Author Topic: How to I change an RGB( array to usuable SFML array?  (Read 2560 times)

0 Members and 2 Guests are viewing this topic.

louwin

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
How to I change an RGB( array to usuable SFML array?
« on: December 03, 2016, 04:59:26 am »
I am a NEWBIE with C++ and have used SFML for a whole week    ;D   I HAVE searched the forums unsuccessfully for a solution  :(

On Windows 10 and SFML 2.4.1 and using VS 2015

How do I change

COLORREF Colours[] = {
        RGB(66, 30, 15),
        RGB(25, 7, 26),
        RGB(9, 1, 47),
        RGB(4, 4, 73),
<<<snip>>>
        RGB(204, 128, 0),
        RGB(153, 87, 0),
        RGB(106, 52, 3) };
 

to a comparable, usable SFML array? (sf::color?)

I have tried various things with my very limited experience  :(

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: How to I change an RGB( array to usuable SFML array?
« Reply #1 on: December 03, 2016, 08:40:29 am »

louwin

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: How to I change an RGB( array to usuable SFML array?
« Reply #2 on: December 03, 2016, 09:50:45 am »
Thanks for your response jamesL    :)

I've tried that but it throws up a few errors   :(

Essentially I replaced RGB with sf::Color    :P

Edit:-  Okay, reread your response and replaced RGB with sf::color::color and it now compiles....    ;D

Thanks jamesL    :D

Told you!  NEWBIE!     :D
« Last Edit: December 03, 2016, 10:02:58 am by louwin »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11008
    • View Profile
    • development blog
    • Email
Re: How to I change an RGB( array to usuable SFML array?
« Reply #3 on: December 03, 2016, 11:05:54 am »
With a std::array (recommended):
std::array<sf::Color, 3> colors = {sf::Color( 66,  30,  15),
                                   sf::Color( 25,   7,  26),
                                   sf::Color(204, 128,   0)};

With a raw array:
sf::Color colors[] = {sf::Color( 66,  30,  15),
                      sf::Color( 25,   7,  26),
                      sf::Color(204, 128,   0)};
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

louwin

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: How to I change an RGB( array to usuable SFML array?
« Reply #4 on: December 03, 2016, 12:04:21 pm »
Thanks for the clarification eXpl0it3r   :)

I used the first form first then to get my modification to work I used the second form. Being a NEWBIE I didn't know why   ;)  I maybe wrong but I THINK I did try the first form but got compile errors (with VS 2015). The errors went away when I changed the sf::Color to sf::Color::Color. Again I don't know why?

Which SHOULD I aim to use and why?   ;)

My array has over 250 occurrences so how would I use the first form and not include the count of occurrences? Just leave off the ", 3"?