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

Author Topic: Letterbox effect using a view  (Read 8387 times)

0 Members and 1 Guest are viewing this topic.

AFS

  • Full Member
  • ***
  • Posts: 115
    • View Profile
Letterbox effect using a view
« on: November 27, 2014, 01:59:10 am »
Hello.

I added a little code example to archieve a letterbox effect when resizing the window, having black bars on the sides in case the aspect ratio of the window is different than the aspect ratio of the view.

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

I was unsure whether this is "wiki material" or not, but I decided to post it regardless. Maybe someone finds it useful.

Any corrections or suggestions are welcome, of course.

Cheers!

Edit: typo.
« Last Edit: December 03, 2014, 06:21:10 pm by AFS »

G.

  • Hero Member
  • *****
  • Posts: 1590
    • View Profile
Re: Letterbox effect using a view
« Reply #1 on: November 27, 2014, 11:28:08 am »
Good idea!  ;)

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Letterbox effect using a view
« Reply #2 on: November 28, 2014, 01:16:01 am »
Aha! You beat me to it! I was going to do just this  ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Letterbox effect using a view
« Reply #3 on: November 28, 2014, 08:49:45 pm »
Nice idea!

Why don't you use
void getLetterboxView(sf::View& view, int windowWidth, int windowHeight)
 
instead of
sf::View getLetterboxView(sf::View view, int windowWidth, int windowHeight)
 
?
It will avoid unnecessary copying.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Letterbox effect using a view
« Reply #4 on: November 28, 2014, 10:31:57 pm »
That would alter the original view (or try to). That might not be desired, or may be a const view (renderWindow.getView() for example).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Cirrus Minor

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Letterbox effect using a view
« Reply #5 on: December 21, 2014, 12:15:05 pm »
Great  :D
I've just integrated it in my current project, it's working fine!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Letterbox effect using a view
« Reply #6 on: December 26, 2014, 03:10:17 am »
santiaboy, this approach has several disadvantages. Such a function cannot be used for initialization, it's impossible to initialize const variables, it needs 2 lines instead of one. The advantage is very questionable: copying small classes is cheap (and assignment is needed anyway, also for output parameters), larger classes can provide move semantics.

Avoid premature optimization, especially if it complicates code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything