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

Author Topic: sf::RenderWindow::Draw() by reference  (Read 2711 times)

0 Members and 1 Guest are viewing this topic.

RaptorIV

  • Newbie
  • *
  • Posts: 30
    • View Profile
sf::RenderWindow::Draw() by reference
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::RenderWindow::Draw() by reference
« Reply #1 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.
Laurent Gomila - SFML developer

RaptorIV

  • Newbie
  • *
  • Posts: 30
    • View Profile
sf::RenderWindow::Draw() by reference
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::RenderWindow::Draw() by reference
« Reply #3 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.
Laurent Gomila - SFML developer

RaptorIV

  • Newbie
  • *
  • Posts: 30
    • View Profile
Hmm.
« Reply #4 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::RenderWindow::Draw() by reference
« Reply #5 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...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: