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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - uzimonkey

Pages: [1]
1
Window / Gracefully degrade resolution
« on: November 02, 2010, 12:50:53 am »
I see where I'm going wrong now.  I've been using App.GetWidth() and App.GetHeight() throughout the code, meaning I'm still drawing everything in screen coordinates.  So my above code (kind of) looked like it was working, but not really.

2
Window / Gracefully degrade resolution
« on: November 02, 2010, 12:22:48 am »
Quote from: "bastien"
In my opinion you should let the user choose the resolution, and use the best available by default. Isn't that possible in your game?


I was thinking of something a little more automated.  Letting the user choose a resolution also doesn't solve the ratio mismatch.  I'm trying to write a function that will set the resolution and just make due with whatever SFML gave you, giving you a scene of the same dimensions and ratio every time.

Here's how I fix windowed mode.  (Also, having to keep the view instance around is very annoying, I only guessed that was the problem and got lucky.)

Code: [Select]

void CorrectWindowedRatio(sf::RenderWindow& App, int width, int height) {
  static sf::View view;
 
  App.SetSize(App.GetWidth(),
              App.GetWidth() * ((float)height / (float)width));
 
  view = sf::View(sf::FloatRect(0, 0, App.GetWidth(), App.GetHeight()));
  App.SetView(view);
}


So I can then do something like this.

Code: [Select]

sf::RenderWindow App(sf::VideoMode(1280, 720), "Window");
// Oops, SFML gave me a window 1024 pixels wide (desktop screen res)
CorrectWindowedRatio(App, 1280, 720);

3
Window / Gracefully degrade resolution
« on: November 01, 2010, 10:36:14 pm »
If I design a game to run at 1280x720 but someone tries to start the game on a lower resolution screen, SFML's behavior is undesirable.  It will open up a window as big as it can (up to the desired resolution), but doesn't preserve aspect ratio.  Is there any way to center the scene in SFML, with black bars on the top and bottom (or left and right, in the case of 4:3 resolutions on a 16:9 screen)?

I tried playing with SetView and sf::View objects, and that kind of works.  The game can still draw outside of the "screen," but that could be fixed by drawing black rects over the portions that are supposed to stay black.  And in windowed mode, you can just set the height of the window to what it should be for the width it gave you.

Of course this wouldn't be ideal.  Scaling down never looks good, but at least it'll work and not be unnaturally stretched.

I was mostly just wondering if there is any supported way to do this, or if anyone has any code that already does this that they'd like to share?

Pages: [1]
anything