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

Author Topic: Calling Text.setString before RenderTexture.create  (Read 2353 times)

0 Members and 2 Guests are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Calling Text.setString before RenderTexture.create
« 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.
« Last Edit: May 27, 2012, 05:03:39 pm by texus »
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Calling Text.setString before RenderTexture.create
« Reply #1 on: May 29, 2012, 03:11:21 pm »
Is there any mac user who can reproduce this?
TGUI: C++ SFML GUI

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Calling Text.setString before RenderTexture.create
« Reply #2 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..
SFML / OS X developer

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Calling Text.setString before RenderTexture.create
« Reply #3 on: May 29, 2012, 05:30:53 pm »
Ok, thanks for testing.
TGUI: C++ SFML GUI