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

Author Topic: [Solved] Stretch to fit screen  (Read 8419 times)

0 Members and 1 Guest are viewing this topic.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
[Solved] Stretch to fit screen
« 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.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Solved] Stretch to fit screen
« Reply #1 on: July 04, 2008, 12:48:05 pm »
I never try, but I think the solution is in sf::View.
SFML / OS X developer

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
[Solved] Stretch to fit screen
« Reply #2 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 ?
Mindiell
----

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Stretch to fit screen
« Reply #3 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.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
[Solved] Stretch to fit screen
« Reply #4 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 :)

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
[Solved] Stretch to fit screen
« Reply #5 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));

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
[Solved] Stretch to fit screen
« Reply #6 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?

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
[Solved] Stretch to fit screen
« Reply #7 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);

 

anything