drjaydenm / SharpText

A GPU accelerated text renderer implemented in C#
MIT License
60 stars 5 forks source link

Text is "fuzzy" #10

Open Perksey opened 4 years ago

Perksey commented 4 years ago

Currently, I'm working on a relatively retro project. As such, i'm trying to make the text look as retro as possible and part of that is making sure the edges of the text aren't "fuzzy" and is as pixelated as possible. Take this text for example:

image

You can see by zooming in that the lines aren't sharp - I expected the only colour in the rendered text to be white and the edges not to be blurred.

image

Is there any way to remove this fuzzy effect?

drjaydenm commented 4 years ago

Hi @Perksey, these "coloured pixels" are part of the text rendering algorithm that I adapted from Evan Wallace's post here. I would take a read of the bottom part of his post that describes the sub-pixel anti-aliasing approach used, it details why this is the case. In most cases it will give a nice result, but for the pixel perfect "crisp" case you are looking for, it may be better to not anti-alias (this may result in poor quality text at small font or screen sizes).

If you are wanting to disable the anti-aliasing, it should be possible by not performing the jitter pass, or at least only doing a single pass with no offset. You can see the code performing that here on line 278. I probably won't be able to get around to this soon myself, but please feel free to pull the source down and play around with it. If you get it working nicely, feel free to let me know and I'll see if I can incorporate it back into this library.