1
Graphics / Letterbox effect using a view - not on position 0,0
« on: May 15, 2016, 12:45:41 pm »
Greetings,
Letterboxing a view when resized to keep the aspect ratio can be done as in the wiki example:
https://github.com/SFML/SFML/wiki/Source:-Letterbox-effect-using-a-view
However, this code assumes the view takes the whole screen and is at position 0, 0, as seen by these variables:
float sizeX = 1;
float sizeY = 1;
float posX = 0;
float posY = 0;
If I have a smaller view, such as a small map on the bottom right corner (therefore, a view not on 0,0 and with a size < window size),
what would be the changes to the code to make that work (it doesn't).
The best I could get was a function that added small increments as the window grew, which would shift it slightly to the right, bottom by changing the initial values (size, pos) to the viewport as expected on the normal screen:
sizeX *= viewRatio / windowRatio;
posX += (1 - sizeX) / 2.0;
Thank you.
Letterboxing a view when resized to keep the aspect ratio can be done as in the wiki example:
https://github.com/SFML/SFML/wiki/Source:-Letterbox-effect-using-a-view
However, this code assumes the view takes the whole screen and is at position 0, 0, as seen by these variables:
float sizeX = 1;
float sizeY = 1;
float posX = 0;
float posY = 0;
If I have a smaller view, such as a small map on the bottom right corner (therefore, a view not on 0,0 and with a size < window size),
what would be the changes to the code to make that work (it doesn't).
The best I could get was a function that added small increments as the window grew, which would shift it slightly to the right, bottom by changing the initial values (size, pos) to the viewport as expected on the normal screen:
sizeX *= viewRatio / windowRatio;
posX += (1 - sizeX) / 2.0;
Thank you.