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

Author Topic: Passing sf::RenderWindow to a function [Solved]  (Read 3144 times)

0 Members and 1 Guest are viewing this topic.

massive_potato

  • Newbie
  • *
  • Posts: 37
    • View Profile
Passing sf::RenderWindow to a function [Solved]
« on: June 30, 2012, 03:41:57 am »
What is the most efficient way to pass a RenderWindow to a function? Is one method preferable compared to another?
« Last Edit: June 30, 2012, 05:50:35 am by massive_potato »

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Passing sf::RenderWindow to a function
« Reply #1 on: June 30, 2012, 05:04:39 am »
You can just pass a reference. (sf::RenderWindow &window); Passing by value won't have the desired result, and passing by pointer opens you up to unnecessary errors(like null values or dangling pointers). References provide the same advantages in this situation with no additional drawbacks.

Since RenderWindow inherits from RenderTarget, I prefer to pass a RenderTarget reference as it implements the same draw functions but could allow you to later change the target of the rendering system from the whole window to a RenderTexture or other object that derives from RenderTarget. I don't know if this usage is recommended, but I've had no problems with it so far.
« Last Edit: June 30, 2012, 05:07:31 am by thePyro_13 »

massive_potato

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Passing sf::RenderWindow to a function [Solved]
« Reply #2 on: June 30, 2012, 05:49:43 am »
I've been passing it that way, but I wasn't sure if there was a faster way to do it (my FPS has been a bit slow). Thanks for clearing things up!

 

anything