SFML community forums
Help => Graphics => Topic started 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.
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?
-
Why do you draw in a constructor? Drawing must happen in your main loop, as shown in the tutorials.
-
The drawing doesn't actually happen in the constructor, it happens in a member function. The member function is called in main.
-
So show us your actual code... we can't help you if what we see is not your code.
-
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:
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.
-
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.
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...