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

Author Topic: Wrong Screen ratio  (Read 143 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 205
    • View Profile
    • Email
Wrong Screen ratio
« on: July 10, 2019, 10:51:50 pm »
Hi,

When I run my SFML games on some PCs which have screens whose width is more than 4/3 of its height, they are displayed with wrong ratio. I always use 800x600.

Is there a solution for this?

Thank you
Pablo

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9221
    • View Profile
    • development blog
    • Email
Re: Wrong Screen ratio
« Reply #1 on: July 10, 2019, 10:54:21 pm »
You mean in fullscreen mode?
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/

Tigre Pablito

  • Full Member
  • ***
  • Posts: 205
    • View Profile
    • Email
Re: Wrong Screen ratio
« Reply #2 on: July 13, 2019, 12:19:51 am »

fallahn

  • Sr. Member
  • ****
  • Posts: 359
  • Buns.
    • View Profile
    • Trederia
Re: Wrong Screen ratio
« Reply #3 on: July 13, 2019, 08:43:01 am »
You can use a view to letterbox the screen for monitors with other aspect ratios:

https://github.com/SFML/SFML/wiki/Source:-Letterbox-effect-using-a-view

Tigre Pablito

  • Full Member
  • ***
  • Posts: 205
    • View Profile
    • Email
Re: Wrong Screen ratio
« Reply #4 on: July 16, 2019, 04:36:08 am »
Hi

In my notebook that had never had that problem it doesn't work.  :(

Everything runs fine but sprites are not drawn. I just see the screen in the color I Cleared()

This is my code (in C#)

GameLevel.GameView = new View(new Vector2f(400, 300), new Vector2f(800, 600));
GameLevel.GameView = Screen.GetLetterboxView(GameLevel.GameView, 800, 600);

Then I call

window.SetView(GameLevel.GameView);

after all calls to

window.Clear();

I didn't handle the Resized event because I'm using fullscreen mode.

Could you tell me what is wrong?
Thanks again  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9221
    • View Profile
    • development blog
    • Email
Re: Wrong Screen ratio
« Reply #5 on: July 16, 2019, 08:18:34 am »
If you request a resolution that doesn't match your monitor ratio, then your monitor will stretch or fit in some ways.
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/

Tigre Pablito

  • Full Member
  • ***
  • Posts: 205
    • View Profile
    • Email
Re: Wrong Screen ratio
« Reply #6 on: July 17, 2019, 12:50:38 am »
Hi all

eXpl0it3r:
On my notebook's monitor I didn't have that issue, but as in other ones I did, I would like to have the same code in my project, and, supposedly it would work fine even on those monitors that don't distort the aspect ratio

I have just tested in a 1440x900 monitor and it doesn't work either

This is my translation of the function from C++ to C# ... maybe there's something wrong

        public static View getLetterboxView(View view, int windowWidth, int windowHeight)
        {
            // Compares the aspect ratio of the window to the aspect ratio of the view,
            // and sets the view's viewport accordingly in order to archieve a letterbox effect.
            // A new view (with a new viewport set) is returned.

            float windowRatio = windowWidth / (float) windowHeight;
            float viewRatio = view.Size.X / (float) view.Size.Y;
            float sizeX = 1;
            float sizeY = 1;
            float posX = 0;
            float posY = 0;

            bool horizontalSpacing = true;
            if (windowRatio < viewRatio)
                horizontalSpacing = false;

            // If horizontalSpacing is true, the black bars will appear on the left and right side.
            // Otherwise, the black bars will appear on the top and bottom.

            if (horizontalSpacing)
            {
                sizeX = viewRatio / windowRatio;
                posX = (1 - sizeX) / 2f;
            }
            else
            {
                sizeY = windowRatio / viewRatio;
                posY = (1 - sizeY) / 2f;
            }

            view.Reset(new FloatRect(posX, posY, sizeX, sizeY));

            return view;
        }
 

Thank you all for your help
« Last Edit: July 17, 2019, 12:52:21 am by Tigre Pablito »