SFML community forums

Help => Window => Topic started by: dabo on July 04, 2008, 12:36:14 pm

Title: [Solved] Stretch to fit screen
Post by: dabo on July 04, 2008, 12:36:14 pm
I'm currently developing a game on my laptop (resolution 1024x768) and today when I tried running the game on my other computer (resolution 1280x1024) all graphics were drawn at the top 1024x768 pixels and not stretched to fit the screen which I was hoping. Is it possible to stretch to fit the screen? I'm using full screen mode.
Title: [Solved] Stretch to fit screen
Post by: Hiura on July 04, 2008, 12:48:05 pm
I never try, but I think the solution is in sf::View.
Title: [Solved] Stretch to fit screen
Post by: Mindiell on July 04, 2008, 12:49:22 pm
Even if you are using full screen, your app must define a resolution for the RenderWindow. Since this resolution is fixed in your app, sprites must be drawn at the same resolution...

No ?
Title: [Solved] Stretch to fit screen
Post by: Laurent on July 04, 2008, 01:00:37 pm
The default behaviour is to keep the default view at the original window dimensions even after a resize, which means your graphics will actually stretch automatically.

However, if your window has a different size at startup, then of course it won't show the same result. All you have to do is to resize the default view to whatever resolution you want to use, regardless of the window size.
Title: [Solved] Stretch to fit screen
Post by: dabo on July 04, 2008, 03:22:32 pm
I've tried changing the default view like in the tutorial but I can't get it to work.

Code: [Select]
rWindow = new sf::RenderWindow(sf::VideoMode::GetMode(0), sTitle, sf::Style::Fullscreen);
sf::View& defaultView = rWindow->GetDefaultView();
sf::VideoMode videoMode = sf::VideoMode::GetMode(0);
defaultView.SetFromRect(sf::FloatRect(0.f, 0.f, videoMode.Width, videoMode.Height));
rWindow->SetView(defaultView);


I have tried using sf::VideoMode::GetDesktopMode() instead of  sf::VideoMode::GetMode(0) with no luck. I'm not guite sure what I'm doing :)
Title: [Solved] Stretch to fit screen
Post by: Avency on July 04, 2008, 03:40:56 pm
Use a fixed value like
Code: [Select]
defaultView.SetFromRect(sf::FloatRect(0.f, 0.f, 1024, 768));
Title: [Solved] Stretch to fit screen
Post by: dabo on July 04, 2008, 03:48:42 pm
Quote from: "Avency"
Use a fixed value like
Code: [Select]
defaultView.SetFromRect(sf::FloatRect(0.f, 0.f, 1024, 768));
Thanks, it worked.

My graphics didn't turn out that great though. Is it possible to change the monitors resolution down to 1024x768 instead, and then set it back to the original when you quit the game?
Title: [Solved] Stretch to fit screen
Post by: Avency on July 04, 2008, 03:55:28 pm
It should be sufficient to create a window with the wanted resolution:
Code: [Select]
sf::RenderWindow App(sf::VideoMode(1024, 768), sTitle, sf::Style::Fullscreen);