I recall reading this post:
http://en.sfml-dev.org/forums/index.php?topic=10855.msg74954#msg74954
Although I did a quick test and it does compile/run (though I think I misread the post now that I look back at it ;]):
#include <SFML/Graphics.hpp>
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Playground");
int main( int argc, char* argv[])
{
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(100, 50));
rectangle.setOutlineColor(sf::Color::Red);
rectangle.setOutlineThickness(5);
rectangle.setPosition(10, 20);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.draw( rectangle );
window.display();
window.clear();
}
return 0;
}
But why exactly would you need it global? If you have your main game loop drawing and updating states, it should be limited to that scope?
Any object can define its own draw function
private:
//we use this so we can have a nice draw(object) format
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void Face::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw( *m_LeftEye );
target.draw( *m_RightEye );
target.draw( *m_Mouth );
target.draw( *m_Nose );
}
That way in main you can just do a window.draw(face)
I scrapped the idea of having a global RenderWindow as i realized there was no need for it and it's just overall bad practice.
I now have a Game class that initializes a window for me.
void Face::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw( *m_LeftEye );
target.draw( *m_RightEye );
target.draw( *m_Mouth );
target.draw( *m_Nose );
}
So basically a class that has multiple calls to the draw function making up the face then when you do window.draw(face), this would produce a full face (theoretically) ?
If it works like that then yes, it would be a good feature to implement in the future when i get the hang of SFML.
I probably gave a little bit of a bad example, but to explain:
I had a face object that I defined that draw function. That draws other objects that I have that also have that draw function defined. So in main I can just do a draw of my face object.
(I'll post some more when I get back home)
the following is all heavy pseudo code
so in main:
renderwindow window
gameLoop()
{
pool events
do stuff
window.clear()
window.draw( ObjectA )
window.display()
}
objecta.hpp
class
{
public:
...
private:
//we use this so we can have a nice draw(object) format
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
....
ObjectB anotherThing;
};
objecta.cpp
void Face::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw( anotherThing );
}
objectb.cpp
another draw function defined
You can peek at what I did w/ http://en.sfml-dev.org/forums/index.php?topic=10363.0