SFML community forums
Help => Window => Topic started by: fallout on September 23, 2012, 09:56:54 am
-
[Using SFML 2.0]
If a function has no access to the current RenderWindow, is it possible to get a handle of the RenderWindow? If not, I'm assuming I must pass a reference to RenderWindow in.
I'm basically trying to create a rectangle shape, initialized in a constructor that is equal to the width of a window and half its height, but I just realized I have no reference to the window, unless I pass it in.
-
Well if the function has no reference/handle to the window, how should it get information from it?
Global objects should not be used and calling OS specific APIs shouldn't be done either.
Easiest part is to either pass in the dimension of the window (e.g. sf::Vector2i) or pass the whole window as reference (e.g. foo(const sf::RenderWindow& wnd)).
If you only need the size then you should only pass the size, if you need more than you can pass a reference to the whole window.
-
Thanks. I was thinking SFML had something similar to SDL_GetVideoSurface() but it doesn't so I just passed as a parameter.
-
Unlike SDL SFML uses a object oriented approach with C++ and avoids as much as possible global functions. )
-
It's not a global function, but sorta is I suppose. Seems to give access to pointer to a static variable.
I suppose it wouldn't make sense though to have a method like that in SFML since SFML is capable of multiple windows, whereas SDL can only have a single window.