SFML community forums

Help => Window => Topic started by: Daniel on September 09, 2021, 11:00:13 pm

Title: Project with responsive window for different resolutions
Post by: Daniel on September 09, 2021, 11:00:13 pm
Hello!

I have developed a cross-platform project using SFML and CMake for macOS, Ubuntu, and Windows. Everything works fine so far, but I have tested this project on three different laptops for each OS stated above and the resolution differs.

I have set the window's resolution of the project to 1280x800. On my mac and on my windows laptop everything is fine as the maximum resolution is above 1280x800... But I have a laptop that is running Ubuntu and which has a maximum resolution of 1366x768 and here, it seems that the objects (rectangles and a grid) are "misplaced" because of the resolution.

My question is how can I make this window responsive? Where should I start? Is it even possible?

Kind regards,

Daniel
Title: Re: Project with responsive window for different resolutions
Post by: eXpl0it3r on September 13, 2021, 04:39:34 pm
Working with different resolutions can be quite tricky.
In order to not create a window that is bigger than your screen resolution, it might be a good idea to check what sf::VideoMode::getDesktopMode() returns and/or use that directly.

Then for the window content, you'll need to adjust the view, to consider the smaller or larger screen space: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php#showing-more-when-the-window-is-resized

And if you want to keep the aspect ratio, you'll have to implement something like the Letterbox Effect: https://github.com/SFML/SFML/wiki/Source%3A-Letterbox-effect-using-a-view
Title: Re: Project with responsive window for different resolutions
Post by: Daniel on September 15, 2021, 06:12:54 pm
Thank you for your response! I will try to implement this feature according to that tutorial.