SFML community forums

Help => Graphics => Topic started by: texus on May 27, 2012, 03:01:46 pm

Title: Calling Text.setString before RenderTexture.create
Post by: texus on May 27, 2012, 03:01:46 pm
I am having a problem with the RenderTexture.
If I call e.g. sf::Text::setString before calling sf::RenderTexture::create then I get a strange result.

In the example code below I am first setting the string to "abcde" before the create call and after the create call I set it to "test". Only the "e" will be drawn on the screen. After looking into this I found out that only the a, b, c, d or e letters would be drawn. So the letters that were not used before the create call are simply not drawn.
Calling window.draw(text) instead of drawing the render texture has the same result!

#include <SFML/Graphics.hpp>

int main()
{
    // Create a new render-window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
   
    // Create a new render-texture
    sf::RenderTexture texture;
   
    sf::Text text;
    text.setString("abcde");
   
    if (!texture.create(500, 500))
        return -1;
   
    text.setString("test");

    // The main loop
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
       
        // Clear the whole texture with red color
        texture.clear(sf::Color::Red);

        // Draw the text on the texture
        texture.draw(text);
       
        // We're done drawing to the texture
        texture.display();
       
        // Now we start rendering to the window, clear it first
        window.clear();
       
        // Draw the texture
        sf::Sprite sprite(texture.getTexture());
        window.draw(sprite);
       
        // End the current frame and display its contents on screen
        window.display();
    }
}

I am on a Mac OS X Lion with SFML2-RC.

EDIT:
I tested it in my VirtualBox and both windows and linux could display the word "test" correctly.
I did also notice however that the texture was drawn a few pixels lower on my windows xp. The red rectangle didn't start at top position 0.
Title: Re: Calling Text.setString before RenderTexture.create
Post by: texus on May 29, 2012, 03:11:21 pm
Is there any mac user who can reproduce this?
Title: Re: Calling Text.setString before RenderTexture.create
Post by: Hiura on May 29, 2012, 05:00:09 pm
No, I can't reproduce it.

But you installed your OS X on a PC, right ? It might come to an incompatible driver, maybe..
Title: Re: Calling Text.setString before RenderTexture.create
Post by: texus on May 29, 2012, 05:30:53 pm
Ok, thanks for testing.