SFML community forums

Help => Graphics => Topic started by: RaptorIV on October 16, 2011, 07:55:22 pm

Title: sf::RenderWindow::Draw() by reference
Post by: RaptorIV on October 16, 2011, 07:55:22 pm
So I try to pass an sf::RenderWindow by reference to my class constructor. When I run sf::RenderWindow.Draw(myShape); i get no errors, but nothing appears in the render window.

Code: [Select]

class Board
{
    public:
        Board(sf::RenderWindow &App);
}

Board::Board(sf::RenderWindow &App)
{

    sf::Shape myShape= sf::Shape::Rectangle(0, 0,  100, 100, sf::Color(0, 0, 0));
    App.Draw(myShape);
}

//in main
sf::RenderWindow App(sf::VideoMode::GetMode(0), "Render Window");
Board gameBoard(App);


So how do can I draw to the renderwindow through reference like this?
Title: sf::RenderWindow::Draw() by reference
Post by: Laurent on October 16, 2011, 08:09:22 pm
Why do you draw in a constructor? Drawing must happen in your main loop, as shown in the tutorials.
Title: sf::RenderWindow::Draw() by reference
Post by: RaptorIV on October 16, 2011, 08:10:55 pm
The drawing doesn't actually happen in the constructor, it happens in a member function. The member function is called in main.
Title: sf::RenderWindow::Draw() by reference
Post by: Laurent on October 16, 2011, 08:13:14 pm
So show us your actual code... we can't help you if what we see is not your code.
Title: Hmm.
Post by: RaptorIV on October 16, 2011, 08:59:22 pm
is there any chance you could just show a generic example of passing a RenderWindow, drawing to it, and then displaying it back in main?

even just passing it to a regular function (forget classes)

like:
Code: [Select]

int hi(RenderWindow App)
{
//draw to app
}

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Othello");
hi(App);
App.Display();
}



this would be appreciated, and im sure this more generic example would be much more beneficial to everyone.
Title: sf::RenderWindow::Draw() by reference
Post by: Nexus on October 16, 2011, 09:22:38 pm
There's nothing special about sf::RenderWindow. You can pass it by reference just as any other C++ object. What you can't do, is pass by value, because sf::RenderWindow is noncopyable.
Code: [Select]
void Fn(sf::RenderWindow& window)
{
    window.Draw(...);
}

If your issue persists, please show us a minimal and complete example code. Otherwise, this will lead to an endless discussion...