Blurred fonts

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Bizun
Prole
Posts: 3
Joined: Mon Mar 26, 2018 4:32 pm

Blurred fonts

Post by Bizun »

Hello! I developed the game on LOVE2D and ran into the problem of blurry text. I attached a screenshot that illustrates the problem.
Image
I need the perfect text, because my game will be text.

Code: Select all

function love.load()
  -- Window settings
  love.window.setMode(800, 600, { vsync = true, msaa = 0, highdpi = true })
  
  -- Font settings
  font = love.graphics.newFont('fonts/FSEX300.ttf', 24)
  love.graphics.setFont(font)

  -- Other code
end

...


function love.draw()
  scale = love.window.getPixelScale()
  love.graphics.scale(scale, scale)
  love.graphics.print("My blurred text", 300, 0)
end
Likewise, if it matters, I'll run the game on top of the Retina.

I attached the love-file, just run it.
Attachments
bf.love
(189.09 KiB) Downloaded 255 times
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Blurred fonts

Post by pgimeno »

Try font:setFilter("nearest", "nearest"). You may also need to use a font size that is a multiple of 16, or alternatively, to adjust the size of the font instead of the scale.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Blurred fonts

Post by zorg »

Fixedsys Excelsior is very picky on the fontsize, i should know, i use it myself; it's either a multiple of 12 or 16 as pgimeno said, to keep it being pixel-perfect.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Bizun
Prole
Posts: 3
Joined: Mon Mar 26, 2018 4:32 pm

Re: Blurred fonts

Post by Bizun »

Thanks! font:setFilter("nearest", "nearest") and font size 16 solve my problem =)
User avatar
hiithaard
Prole
Posts: 3
Joined: Wed Jul 01, 2020 4:49 pm

Re: Blurred fonts

Post by hiithaard »

Well there's one workaround... You can use love.graphics.scale
But still you will have to keep the font size of a multiple of 16

Here's how to do it

Code: Select all

love.graphics.setDefaultFilter('nearest', 'nearest')
love.graphics.push()
love.graphics.scale(0.5, 0.5) -- by whatever size you want to rescale
love.graphics.print("text", x, y)
love.graphics.pop() -- because 0.5 will affect everything
Note: You will have to adjust the coordinates accordingly after rescaling
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Blurred fonts

Post by zorg »

hiithaard wrote: Wed Jul 01, 2020 5:31 pm Well there's one workaround... You can use love.graphics.scale
That might work for downscaling, but im not so sure about upscaling; also, you would probably need to stick to integral numbers........ oh, welcome to 2018 i guess. :v
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: Blurred fonts

Post by milon »

I've got a question for 2018, lol. Why is everyone saying use a font size that's a multiple of 16 (or 12)? And does that still hold today?
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Blurred fonts

Post by pgimeno »

That applies to the particular bitmapped font that the OP used. Bitmapped fonts are made for specific sizes; the specific size to use depends on the font. For truetype fonts, that shouldn't be an issue.

Do you have an issue with a blurred font?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Blurred fonts

Post by zorg »

Technically, fixedsys excelsior is also a truetype font, it's just designed with pixel-like square shapes in lieu of truetype actually supporting bitmap fonts; due to that, and how TT renderers work (afaik), if you don't draw/render it as a multiple of size 16 (that it was designed for), then you'll get artifacts/distortion.

You can see this most easily if you have the font installed when you open a simple notepad, type a sentence, then change the size from let's say 12 to 11 (or 16 to 15; depends on what program you're using the font in whether the recommended size is 16 or 12 or whatever.) a one-point difference will just squish the text a tiny bit.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests