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

Author Topic: Can a RenderTexture be resized?  (Read 2068 times)

0 Members and 1 Guest are viewing this topic.

Mithra

  • Newbie
  • *
  • Posts: 4
    • View Profile
Can a RenderTexture be resized?
« on: February 22, 2019, 05:14:44 pm »
Hey guys!

I have a dynamic width requirement for a sprite generated from a RenderTexture, but redundant calls to rt.create don't seem to reinitialize it to the new width ( apparently I'm not supposed to do it this way )

Is there a proper way to destroy and recreate a RenderTexture?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Basically I've created a custom font class that makes a single sprite out of a line of text, but only when the text changes.  If I call create redundantly, I see graphical artifacts at the edge of my sprite, which tells me the texture probably didn't resize.  Hopefully there is a better solution than creating the render texture once to the entire width of the window (since I may have dozens of these objects)

This is what I'm doing when the text changes..

Quote
rt.create( width, height);

rt.clear( sf::Color( 0,0,0,0));

DrawText( pszString, rshader, tint);

rt.display();

textureText = rt.getTexture();
      
spriteText.setTexture( textureText);

Any feedback is appreciated, thank you!!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can a RenderTexture be resized?
« Reply #1 on: February 22, 2019, 05:39:18 pm »
Please read the documentation first.

But a much better (more efficient) solution would be to give the RenderTexture a maximum size, then leave it untouched and instead only adjust the sprite's textureRect. Which is a free operation compared to re-creating a RenderTexture. You don't even need to call sprite.setTexture again as long as you don't re-create the RenderTexture.
Laurent Gomila - SFML developer

 

anything