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

Author Topic: Why does RenderTarget class not declare the display() function?  (Read 2149 times)

0 Members and 1 Guest are viewing this topic.

smurf

  • Newbie
  • *
  • Posts: 33
    • View Profile
Both of it's children, RenderWindow and RenderTexture have a display() function. Why not define it in the base class of RenderTarget?

Why do I care?

I want to re-use the same code for drawing to a window and drawing to a texture. So I want to be able to pass in the parent object (RenderTarget) into a drawing class that will just draw and not care about whether it is to a window or a texture.

But the lack of the display() function is preventing this.  What am I missing? This seems like an obvious thing to do.

Thanks,

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Why does RenderTarget class not declare the display() function?
« Reply #1 on: May 08, 2017, 09:13:24 am »
It's just a design thing I guess. A render target doesn't have to know when it's "done"  (think unbuffered rendering).

I think the problem here is the fact that you're trying to create a "drawable", just not the way SFML wants you to do.

So rather than calling something like `yourObject.draw(renderTarget);` in your code, you're supposed to call `renderTarget.draw(yourObject)`.

The latter can be achieved by subclassing `sf::Drawable`. There's nothing wrong in making this your "super draw everything class".

As an alternative workaround – if you insist on your interface – you could just overload the method called, once for `sf::RenderTexture*` and once for `sf::RenderWindow*`. This also works for a constructor, just make sure to store which subclass of `sf::RenderTarget` you actually received.

 

anything