SFML community forums

Help => Graphics => Topic started by: rajhansk on September 05, 2017, 02:55:17 pm

Title: How Do I change background color of my window?
Post by: rajhansk 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...

Title: Re: How Do I change background color of my window?
Post by: Laurent on September 05, 2017, 03:03:41 pm
Seriously?

https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1RenderTarget.php#a6bb6f0ba348f2b1e2f46114aeaf60f26
Title: Re: How Do I change background color of my window?
Post by: rajhansk 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.

Title: Re: How Do I change background color of my window?
Post by: rajhansk 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)   )
Title: Re: How Do I change background color of my window?
Post by: Laurent 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.
Title: Re: How Do I change background color of my window?
Post by: rajhansk on September 05, 2017, 03:35:26 pm
I am learning :) :) :)
Title: Re: How Do I change background color of my window?
Post by: rajhansk 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.
Title: Re: How Do I change background color of my window?
Post by: eXpl0it3r on September 05, 2017, 03:54:55 pm
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. ;)
Title: Re: How Do I change background color of my window?
Post by: kepler0 on September 09, 2017, 06:28:00 pm
You have 16 posts and all of them are asking how to do basic things.

 :-\
Title: Re: How Do I change background color of my window?
Post by: Teknol 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
Title: Re: How Do I change background color of my window?
Post by: Not Your Average Joe 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!!!
Title: Re: How Do I change background color of my window?
Post by: kojack 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.
Title: Re: How Do I change background color of my window?
Post by: Hapax 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!
Title: Re: How Do I change background color of my window?
Post by: It_Helped_Me 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