SFML community forums

Help => Graphics => Topic started by: akhena on September 04, 2011, 03:59:28 pm

Title: Text rendering problem
Post by: akhena on September 04, 2011, 03:59:28 pm
Hello,

I finally made a "minimal" code to show the bug I had when displaying some text. I know this problem doesn't happen on all computers, as it doesn't on my laptop. Nevertheless, I thought it might be of interest.

If anyone has an idea to help me find the culprit, I would appreciate.

Code: [Select]
#include <iostream>
#include <list>
#include <vector>
#include <SFML/Graphics.hpp>

using namespace std;

int main()
{
    sf::Font font;
    // Create a window and its view
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");
    // Load font
    if (!font.LoadFromFile("comic.ttf"))
        {
            std::cout << "Could not load font." << std::endl;
            return EXIT_FAILURE;
        }

    typedef std::list<std::string> StringList;
    StringList stringList;

    stringList.push_back("Test avec le texte");
    stringList.push_back("éèàêzZaA ù");
    stringList.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    stringList.push_back("abcdefghijklmnopqrstuvwxyz");
    stringList.push_back("éèàê");

    std::vector<sf::Text> textLines;
    float lastLinePosition = 0.f;

    for(std::list<std::string>::iterator line = stringList.begin(); line != stringList.end();
            ++ line)
    {
        sf::Text textLine(*line, font, 20);
        textLine.SetColor(sf::Color::Red);
        sf::Vector2f position;
        position.x = 10.f;
        position.y = std::floor(10.f + lastLinePosition + 0.5);
        textLine.SetPosition(position);
        textLines.push_back(textLine);
        lastLinePosition += font.GetLineSpacing(20);
    }

    // Start the game loop
    while (window.IsOpened())
    {
        // Process events
        sf::Event event;
        while (window.PollEvent(event))
        {
            // Close window : exit
            if (event.Type == sf::Event::Closed)
                window.Close();
        }

        // Clear screen
        window.Clear();
        for(std::vector<sf::Text>::iterator line = textLines.begin(); line != textLines.end();
                    ++line)
        {
            window.Draw(*line);
        }
        // Update the window
        window.Display();

    }
    return EXIT_SUCCESS;

}

Of course you'll need comic.ttf in your folder. But I guess this font can be found on most computers...

I'm running this on an AMD 2400++ with an ATI Radeon 9600 graphic card. I already tried to install the latest driver, with no success.

You can find my print screen here : http://imageshack.us/f/684/sfmltext.jpg
The problem appears on the 4th line.
Title: Text rendering problem
Post by: Lo-X on September 04, 2011, 04:13:41 pm
Ok, sorry for my answer...
I was sure I've seen a topic like that recently...
Need some rest...
Title: Text rendering problem
Post by: Laurent on September 04, 2011, 04:14:33 pm
It works for me, so... it will be hard to find out what's wrong :?

Quote
I think there are a lot of topic about that on SFML forum...
Try the Search function

???
Title: Text rendering problem
Post by: Lo-X on September 04, 2011, 04:28:36 pm
Ok i'm not mad, I've effectively seen a question like that, but on French part of the forum.

Link : http://www.sfml-dev.org/forum-fr/viewtopic.php?t=3747

The problem was an "old" build of SFML2
Have you the last build of SFML ?
Title: Text rendering problem
Post by: akhena on September 04, 2011, 06:13:02 pm
Thanks for the link, unfortunately it doesn't solve my problem.   :(
Title: Text rendering problem
Post by: easy on September 07, 2011, 11:16:09 pm
Hi!

The same issue here:
(https://legacy.sfmluploads.org/cache/pics/113_text-artifact.png)

Is there a solution or a workaround for this?
Title: Text rendering problem
Post by: easy on September 10, 2011, 12:47:53 am
Today I've tested it on Windows XP and Windows 7, and the same glitch is present, see the image above.
Title: Text rendering problem
Post by: Kian on September 10, 2011, 03:52:50 am
I found the problem, you're using comic sans. Switch to pretty much any other font and it'll look a lot better ;)

Just kidding, a bit.
Title: Text rendering problem
Post by: easy on September 10, 2011, 03:25:06 pm
Quote from: "Kian"
I found the problem, you're using comic sans.


Heheh, no it's 'Cheeseburger', the basic font that came along with the pong example in SFML! :)
Title: Text rendering problem
Post by: mbro2k on September 25, 2011, 08:34:44 pm
I am also having this problem unfortunately.
I'm using the latest sfml2 version.
It seems to only happen on some computers.
I tried a few different ttf fonts.

On windows 7 64-bit I actually have no problems,
but a friend sees it on their machine with vista64, intel graphics.

I can also see the problem when using a windowsXP 32-bit on a virtual machine.