Artifacts when drawing scaled text

Monkey Forums/Monkey Programming/Artifacts when drawing scaled text

Grey Alien(Posted 2011) [#1]
Hi all, I made my own font and used Set Font and then used Scale 2,2 to draw it, and after I figured out that the x,y DrawText coords are also scaled, I finally got an output like this:


(actual font I'm using has a transparent background)

You can see there are various artifacts around the letters. I compiling as HTML 5 and viewing in Firefox. Perhaps it's better in other targets (not tested yet).

As you can see my font chars are 12x12 and I've left a 2 pixel gap on the right and beneath each letter. What seems to be happening is each letter is drawing a small amount of the letter underneath it and the letter to the right of it from the main font texture.

I'm sure I could fix this by shifting each of my characters one pixel right and down so that there's a gap all around each letter, although this will screw up the comma and semi-colon unless I add yet more padding.

I'm just wondering if people have found a better solution, apart from writing their own bitmap font class (and would that also suffer from the same problem anyway?)

A secondary issue is, when scaled up the text is smoothed. Normally this is a good thing, but in this case I'd like to turn off smoothing. Is that possible?

Thanks for any pointers!


therevills(Posted 2011) [#2]
double post :/


therevills(Posted 2011) [#3]
With the artifacts, have a mess around with the XYPadding flag in LoadImage...

A secondary issue is, when scaled up the text is smoothed. Normally this is a good thing, but in this case I'd like to turn off smoothing. Is that possible?


You need to hack mojo:

http://www.monkeycoder.co.nz/Community/posts.php?topic=993


Grey Alien(Posted 2011) [#4]
Yeah I used the XYPadding flag but it chopped off the top and left edges of pixels. I thought it was going to pad my image automatically, but instead it assumes my image is already padded. Not quite the same.


Grey Alien(Posted 2011) [#5]
Hey great hack, I liked your example in Flash. I prefer not to hack mojo unless absolutely necessary. Would love it if this hack was added to the "official" version.


therevills(Posted 2011) [#6]
I havent really played much with the XYPadding to be honest...

Actually I think the artifacts might be due to the filtering, so I would alter Mojo and see if that fixes both your issues.


Gerry Quinn(Posted 2011) [#7]
AngelFont is your friend, IMO.


dmaz(Posted 2011) [#8]
and so is http://ooeyug.com/texpac


Grey Alien(Posted 2011) [#9]
Thanks, will check out.


Rus(Posted 2011) [#10]
@Grey Alien
I had a similar issue with a texture atlas of sprites that I'm using in my game. The only method I found that worked is what you mentioned in the beginning. I have a 1 pixel padding around each sprite in the atlas. This should be the case for bitmap font sheets as well. I'm convinced it's the filtering that is causing it, and I haven't found a way of turning it off or changing the filtering method.


Grey Alien(Posted 2011) [#11]
Thanks Rus. I'll certainly bear this in mind for all future stuff I do in Monkey. I used to pad images/textures in BlitzMax anyway due to minor issues but it was never as bad as this.