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

Author Topic: Project with responsive window for different resolutions  (Read 430 times)

0 Members and 1 Guest are viewing this topic.

Daniel

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Project with responsive window for different resolutions
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9909
    • View Profile
    • development blog
    • Email
Re: Project with responsive window for different resolutions
« Reply #1 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
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Daniel

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Project with responsive window for different resolutions
« Reply #2 on: September 15, 2021, 06:12:54 pm »
Thank you for your response! I will try to implement this feature according to that tutorial.