SFML community forums

Help => General => Topic started by: Tigre Pablito on July 10, 2019, 10:51:50 pm

Title: Wrong Screen ratio
Post by: Tigre Pablito 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
Title: Re: Wrong Screen ratio
Post by: eXpl0it3r on July 10, 2019, 10:54:21 pm
You mean in fullscreen mode?
Title: Re: Wrong Screen ratio
Post by: Tigre Pablito on July 13, 2019, 12:19:51 am
You mean in fullscreen mode?

Yes
Title: Re: Wrong Screen ratio
Post by: fallahn 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
Title: Re: Wrong Screen ratio
Post by: Tigre Pablito 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  :)
Title: Re: Wrong Screen ratio
Post by: eXpl0it3r 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.
Title: Re: Wrong Screen ratio
Post by: Tigre Pablito 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