SFML community forums
Help => General => Topic started 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
-
You mean in fullscreen mode?
-
You mean in fullscreen mode?
Yes
-
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
-
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 :)
-
If you request a resolution that doesn't match your monitor ratio, then your monitor will stretch or fit in some ways.
-
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