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

Author Topic: Strange Rendering Behaviour with sf::Text and sf::RenderTexture  (Read 4129 times)

0 Members and 1 Guest are viewing this topic.

gamepopper

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« on: November 13, 2015, 01:37:00 am »
So I've been having this weird rendering issue. My game project uses very specific text rendering, which requires me to paste text onto a texture, and then render it as a sprite or another render entity using VertexArrays. Below is one example of how I achieve this:

if (!VContent::FindTexture("player"))
        {
                sf::RenderTexture renderTex;
                renderTex.create(18, 26);

                sf::Font font;
                VContent::LoadFont("Assets\\lucon.ttf", font);
                sf::Text text = sf::Text("@", font, 32);
                text.setColor(sf::Color::White);
                text.setStyle(sf::Text::Regular);
                text.setPosition(0, -7);
                renderTex.draw(text);
                renderTex.display();

                VContent::StoreTexture("player", renderTex.getTexture());
        }

VContent by the way, is my content manager, which I use to store and load textures and other copyable assets essentially anywhere in my project. It stores textures like so:

bool VContent::StoreTexture(string name, sf::Texture texture)
{
        if (!FindTexture(name))
        {
                sf::Texture tex(texture);
                textureDir.insert(textureDir.begin(), std::pair<string, sf::Texture>(name, tex));

#if _DEBUG
                cout << name << " stored." << endl;
#endif
               
                return true;
        }

#if _DEBUG
        cout << "Error storing texture: " << name << endl;
#endif

        return false;
}

Anyway, on my home PC (see left image) it displays like normal with the text being rendered with the correct characters, but when I was testing on another PC (see image right), I was getting incorrect characters and random artefacts.



As far as hardware is concerned, there isn't much difference as they are both have Intel Core iSeries CPU, decent hard drive space and are both relatively high performance machines (although my home PC has a dedicated gaming graphics card, but I haven't discovered if the other PC has one itself).

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« Reply #1 on: November 14, 2015, 06:22:19 pm »
you remove rebdertexture everyframe as i see thats is - conputer slowdown and memory leaks aka artefacts

gamepopper

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« Reply #2 on: November 15, 2015, 09:56:02 pm »
you remove rebdertexture everyframe as i see thats is - conputer slowdown and memory leaks aka artefacts

I don't think so, the above method I used is only used once when creating a texture, usually in initialisation. I do also use a render texture to render the entire scene, set its texture to a sprite and then scale it, but the render texture is created once and only removed when the application is closed.

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« Reply #3 on: November 15, 2015, 10:18:59 pm »
Just out of curiosity.. you don't clear the render texture first? I can understand in theory you shouldn't need to if you just created it, but it also feels like one of those instances where behaviour may be undefined, giving different results between different drivers/implementations

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« Reply #4 on: November 15, 2015, 10:35:27 pm »
Quote
I can understand in theory you shouldn't need to if you just created it
I don't think the initial content of a texture is clearly defined in the OpenGL standard. So yes, it must be cleared first (or completely overwritten).

Quote
bool VContent::StoreTexture(string name, sf::Texture texture)
{
    if (!FindTexture(name))
    {
        sf::Texture tex(texture);
        textureDir.insert(textureDir.begin(), std::pair<string, sf::Texture>(name, tex));
 
Wow... 3 expensive texture copies in 3 lines of code, where you only need 1 :P
Laurent Gomila - SFML developer

gamepopper

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« Reply #5 on: November 16, 2015, 10:31:42 am »
I don't think the initial content of a texture is clearly defined in the OpenGL standard. So yes, it must be cleared first (or completely overwritten).

I think if I went through my code right now, it's sometimes I do and sometimes I don't. I'll have to check and add clear calls to all of them if I want to check.

Quote
Wow... 3 expensive texture copies in 3 lines of code, where you only need 1 :P

Yeah I realised soon after I posted that I needed to update this code, should really be passing in by reference. ^^;
« Last Edit: November 16, 2015, 10:34:34 am by Laurent »

gamepopper

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Strange Rendering Behaviour with sf::Text and sf::RenderTexture
« Reply #6 on: November 17, 2015, 03:02:22 pm »
Small update:
So I did what you've guys have suggested an added renderTex.clear(sf::Color::Transparent) after every create function call.



It appears to be working, aside from the floor but that's just one graphic that I can check on.

I've also reduced the amount of texture copies in my Content Manager class as well.  :P