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

Author Topic: SFML Text Artifacts  (Read 7920 times)

0 Members and 1 Guest are viewing this topic.

kpulv

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML Text Artifacts
« on: June 18, 2013, 01:58:08 am »
Using the SFML Text in the DotNet binding I'm having problems with the text class.  I have tried multiple font sizes, and multiple fonts, and multiple strings, all with the same results.





You can see in this example there are stray pixels being rendered in the upper left hand corner of the text.  It seems to always appear on the upper left of the first character's bounding box, and it also seems like it is smaller than a single pixel because moving the text around the screen causes the artifact to appear and reappear.

I have not tried the C++ version yet, but I have spoken to at least one other DotNet developer who is experiencing the same issue with the DotNet binding of SFML.

Does anyone know what's going on or how to fix this?

Update
A friend of mine tried Text in pySFML and found the same result:


Update 2
It seems that further investigation shows that this artifact will appear when the text is drawn at a y coordinate of 0 to 0.5.  So for example if the text is at Y 50.1, the artifact will appear.  However, at 50.51, the artifact will not appear, and then it will appear again at 50.5.

It would seem that rounding is the solution -- however this is not a very good solution as this results in a loss of fidelity in drawing, as things become jittery when moving when they are always rounded to the nearest integer.
« Last Edit: June 18, 2013, 02:48:23 am by kpulv »

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: SFML Text Artifacts
« Reply #1 on: June 18, 2013, 03:00:40 am »
I can confirm this. It also happens when I set the scale of a Text object.

Is there a way to set smoothing on the texture used to render the text? I have a feeling that might help things.

kpulv

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: SFML Text Artifacts
« Reply #2 on: June 18, 2013, 03:28:01 am »
Strangely enough right now this appears to be a work around.

Create a dummy text object, like so:
Text dummytxt = new Text("Å", font, 100);

Then create your actual text:
Text testtext = new Text("QUICK!", font, 100);

Then only draw the actual text:
Window.draw(testtext);

This seems to prevent the offending pixel from appearing.

Atrius

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML Text Artifacts
« Reply #3 on: June 18, 2013, 05:55:03 am »
@TechRogue-- In C#, I tried drawing to a RenderTexture with smooth set to false, and then copying that to a sprite and drawing it on the window. It still occurs. So it doesn't appear to be smoothing related.


I was able to repro this using C++ with the SFML 2.0 windows binaries. It's not the C# wrapper.

I don't see the extra pixel when I create and draw the Text object, but if I scale it, it's instantly visible.


        sf::RenderWindow window(sf::VideoMode(1024, 768), "Test Window");

        sf::Font font;
        if (!font.loadFromFile("c:\\windows\\fonts\\arial.ttf")) return EXIT_FAILURE;

        sf::Text text("test", font, 100);
        text.setPosition(50,50);
        text.setScale(2,2);

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }
                window.clear();
                window.draw(text);
                window.display();
        }

« Last Edit: June 18, 2013, 05:59:38 am by Atrius »

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: SFML Text Artifacts
« Reply #4 on: June 18, 2013, 04:35:09 pm »
I was referring to the actual texture used as a source for the font, not the render texture.  ;)

Noticing how the pixel shows up on both 't's in your example, I'm guessing it's a matter of how the source texture is created.

kpulv

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: SFML Text Artifacts
« Reply #5 on: June 18, 2013, 09:56:33 pm »
Yeah, it has something to do with how the texture for the font is created.  Apparently the upper left corner of the texture has a small white 2x2 box placed on it: https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Font.cpp#L584

So that little set of pixels will show up on the first character of your string because of pixel interpolation (I think?)  Making a dummy text object (see my previous post) with a character you'll never use, like Å or something, will place the dot next to that Å character, and the rest of your characters will be safe.

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: SFML Text Artifacts
« Reply #6 on: June 18, 2013, 10:56:22 pm »
Interesting...I wonder if that's necessary any more? Ever since the new graphics API was introduced, underlining is done by adding vertices to the vertex array. That block of code dates back to 2009 (scroll all the way down).

Atrius

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML Text Artifacts
« Reply #7 on: June 19, 2013, 04:12:47 am »
Sorry I haven't had time to dig into this. This was the first location I tweeted but Kyle mentioned he was working in C# and didn't have it setup to compile the libs. I got home from work and looked into it.

These pixels are still required for the underline to work. If you remove the code that sets these pixels it fixes the problem but also makes it so underline doesn't work.

This confirms the issue is caused by the code at SFML/Graphics/Font.cpp:584. However, it also brings to light that you cannot remove this without losing functionality.

When I get some more time I'll look into if this can be improved and retain the functionality.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML Text Artifacts
« Reply #8 on: June 19, 2013, 08:12:09 am »
You should create a ticket on the task tracker, I already have an idea how to fix it :)
Laurent Gomila - SFML developer

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: SFML Text Artifacts
« Reply #9 on: June 19, 2013, 09:53:57 pm »
I'll open the issue if nobody else is going to. I didn't want to jump on it because I'm not the one who found it in the first place.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML Text Artifacts
« Reply #10 on: June 23, 2013, 10:44:32 pm »
It's fixed, thanks for your help :)
Laurent Gomila - SFML developer