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

Author Topic: Glitch on font rendering (subpixel) and workaround  (Read 1874 times)

0 Members and 1 Guest are viewing this topic.

Cleroth

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Glitch on font rendering (subpixel) and workaround
« on: June 13, 2013, 02:37:21 pm »
I've been trying to render text on SFML with fractional positions, and it all worked fine except for some white pixels appearing at the top left of each glyph:


I thought it was the texture bleeding from another part of the font texture, but I increased the padding and it didn't help.

I found a workaround which offsets the top boundary of the glyph by +1, at Text::updateGeometry:
int left   = glyph.bounds.left;
int top    = glyph.bounds.top+1;
int right  = glyph.bounds.left + glyph.bounds.width;
int bottom = glyph.bounds.top+1  + glyph.bounds.height;

float u1 = static_cast<float>(glyph.textureRect.left);
float v1 = static_cast<float>(glyph.textureRect.top+1);
float u2 = static_cast<float>(glyph.textureRect.left + glyph.textureRect.width);
float v2 = static_cast<float>(glyph.textureRect.top+1  + glyph.textureRect.height);

I'm not entirely sure if this code is correct, it probably cuts off a part of the glyph or something, but so far I haven't seen anything noticeable in my fonts. It's certainly better than having a conspicuous pixel at the top left of nearly every glyph.

After spending three hours for a fix to this problem I'm content with this solution, but I believe the real problem probably lies within Font::loadGlyph. It would be nice to see it properly fixed.
Other than that... I'm having a great time using SFML. I moved from a different engine to this and I don't regret it.

Also, it would be nice having text alignment in hand.

Thank you!
« Last Edit: June 13, 2013, 02:39:30 pm by Cleroth »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Glitch on font rendering (subpixel) and workaround
« Reply #1 on: June 13, 2013, 02:59:28 pm »
Using official SFML 2.0?
Laurent Gomila - SFML developer

Cleroth

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Glitch on font rendering (subpixel) and workaround
« Reply #2 on: June 13, 2013, 09:33:50 pm »
Yes. It happens on SFML 2.0, Visual C++ 11 (2012) - 32 bits. I downloaded a snapshot of current sources (da96ec5811d67c6692751c27b5dc905a23dce3ed) yesterday and it did the same, and that's where I put the workaround.
« Last Edit: June 13, 2013, 09:37:26 pm by Cleroth »

Cleroth

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Glitch on font rendering (subpixel) and workaround
« Reply #3 on: June 13, 2013, 09:56:23 pm »
I have a GTX 670. I've tried it on my laptop, both with the integrated graphics (Intel HD Graphics 2000) and the High performance (GT 635M). The bug happens on all of those.

Note that it's easier to notice the glitch when you move the text slowly. All I did was make the text follow a game character, which smoothly goes from point A to point B (thus all the fractional values).
« Last Edit: June 14, 2013, 02:55:13 am by Cleroth »

 

anything