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

Author Topic: How Do I change background color of my window?  (Read 30929 times)

0 Members and 1 Guest are viewing this topic.

rajhansk

  • Newbie
  • *
  • Posts: 21
    • View Profile
How Do I change background color of my window?
« on: September 05, 2017, 02:55:17 pm »
How Do I change background color of my window? It is by default back.

I searched for it in tutorials but I couldn't find...


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

rajhansk

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: How Do I change background color of my window?
« Reply #2 on: September 05, 2017, 03:14:40 pm »
Tbh, I did find that but I don't know how to implement that...

I am still a beginner and I don't know how to read the documentation.


rajhansk

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: How Do I change background color of my window?
« Reply #3 on: September 05, 2017, 03:24:52 pm »
I mean in this following line what is in the bracket ?? what should I type in here, should I just type the name of color or should I write the color codes??
void sf::RenderTarget::clear(const Color &    color = Color(0, 0, 0, 255)   )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How Do I change background color of my window?
« Reply #4 on: September 05, 2017, 03:30:51 pm »
You may want to learn C++ before trying to write a graphical application involving a 3rd-party library. Really.
Laurent Gomila - SFML developer

rajhansk

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: How Do I change background color of my window?
« Reply #5 on: September 05, 2017, 03:35:26 pm »
I am learning :) :) :)

rajhansk

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: How Do I change background color of my window?
« Reply #6 on: September 05, 2017, 03:45:45 pm »
Anyway, back to my question,

Can you guide regarding this?

How do I read the documentation of SFML??

That will be really helpful.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: How Do I change background color of my window?
« Reply #7 on: September 05, 2017, 03:54:55 pm »
Edit: For example: window.clear(sf::Color::Red); changes the background color to red.

We're here to help people with SFML and not teach people C++ basics.
If you don't understand a simple function signature, then you really have to spend more time just learning pure C++.
Here's a list of recommended C++ books: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

Also, there are enough examples out there showing how to pass a color. ;)
« Last Edit: September 12, 2024, 09:57:15 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/

kepler0

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: How Do I change background color of my window?
« Reply #8 on: September 09, 2017, 06:28:00 pm »
You have 16 posts and all of them are asking how to do basic things.

 :-\
Zzz

Teknol

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: How Do I change background color of my window?
« Reply #9 on: September 10, 2017, 06:06:33 am »
I don't really know but I assume it's like this
Color(red, green, blue, alpha)

So (255, 0, 0, 255) will make it a bold red maybe??

I've recently just started sfml after learning c++


Sent from my iPhone using Tapatalk

Not Your Average Joe

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: How Do I change background color of my window?
« Reply #10 on: October 15, 2023, 11:38:23 pm »
I literally just registered to this forum just so I can say this:

You guys are absolutely annoying and this forum sucks.

SFML is not intuitive, even if you know C++ no matter what you say.
You are just a bunch of know-it-all-but-wont-share-because-you-are-a-dick geeks.
Isn't the purpose of a forum to help and be helped? Yall not helpful at all, and I've seen many posts in here.

As you know, besides the official documentation on the SFML website, there is not much out there online on SFML, probably because no one cares for it, and we are out here trying to use it (in my case for school) because we have to. Actually, not even the official documentation is that good. Are you guys in charge of that too? You must be!
Yet, there is this one forum that exists (this one), with all this "knowledgeable" people that wont ever answer a question, simple, or hard. Im starting to think yall dont know what u talking about. How are we supposed to learn this shit? Tarot?

Someone shared a link for some RenderTarget color crap, that was not the question.
Anyway, block me, delete me, or maybe, become a better person, IDC

ANYWAY HERE IS THE ANSWER:

you have something like
sf::RenderWindow window(sf::VideoMode(size, size),....);

inside of the while loop for the window.open you will have this call before drawing your images or whatever you are drawing:
window.clear();
right?

You simply pass the color there, such as:
window.clear(sf::Color::White);
or whatever combination you want such as (0, 0, 255)

Thats it! You are very welcome!

OH MY GOD
I think my hand just broke after answering this. I understand now   ::)

peace!!!
« Last Edit: October 15, 2023, 11:49:43 pm by Not Your Average Joe »

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: How Do I change background color of my window?
« Reply #11 on: October 17, 2023, 01:55:34 am »
Someone shared a link for some RenderTarget color crap, that was not the question.
A minor nitpick, but that link wasn't crap and it did apply to the question.
RenderWindow inherits from RenderTarget. It's RenderTarget that provides the clear() function, not RenderWindow.

Now the creator of SFML could have been a bit politer, but the link he gave did match the question.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How Do I change background color of my window?
« Reply #12 on: October 18, 2023, 12:08:17 pm »
RenderWindow inherits from RenderTarget. It's RenderTarget that provides the clear() function, not RenderWindow.
That's true and maybe it's not too obvious at first.
If you go to RenderWindow's documentation and click on clear it links to the Render Target's clear documentation. If you only see the "target", you may initially wonder what that has to do with "window".
Maybe a better documentation link would have been the window one:
https://www.sfml-dev.org/documentation/2.6.0/classsf_1_1RenderWindow.php
and then point out the "clear" method (which would then take you to "target" but you may more likely understand why).

I literally just registered to this forum just so I can say this:
[...]
You are very welcome!
Welcome to the forum!
Thank you for helping the OP (from 2017); I'm sure this is exactly what they have been waiting for.

I think my hand just broke after answering this.
I hope your hand improves soon. Get well soon!
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

It_Helped_Me

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How Do I change background color of my window?
« Reply #13 on: November 05, 2023, 02:30:47 pm »
I literally just registered to this forum just so I can say this:
[...]
You are very welcome!
Welcome to the forum!
Thank you for helping the OP (from 2017); I'm sure this is exactly what they have been waiting for.

peep my username