Fonts blurry on low pixel size when drawn onto canvas[SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
nGear
Prole
Posts: 3
Joined: Sun Apr 10, 2016 5:49 pm

Fonts blurry on low pixel size when drawn onto canvas[SOLVED]

Post by nGear »

Hey guys,
recently picked up love again(have been playing for a very short timespan with it about a year ago)

My problem is that when i create a new font with, for example a size of 12, it gets way too blurry.
Screenshot:
Image

but it should look like this:
Image

As you can see on the first screen, it is blurred (it's readable, but the text isn't sharp at all, like on the second screen)

The text is drawn onto a canvas, that seems to be the case because the second screen was taken without the print being drawn onto a canvas and it looks just like i want it to look like.

Important code snippets:

creating of canvas

Code: Select all

staticCanvas = love.graphics.newCanvas(677, 343)
drawing onto canvas

Code: Select all

local oldBlend = love.graphics.getBlendMode()
love.graphics.setCanvas(staticCanvas)
	love.graphics.clear()
	love.graphics.setBlendMode('alpha')
	drawcall()
	love.graphics.setBlendMode(oldBlend)
love.graphics.setCanvas()
drawcall

Code: Select all

local font = game.loadFont("consolas.ttf", 12)
love.graphics.setFont(font)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setBlendMode("alpha")
local height = font:getHeight()
local lines = {"Line 1", "Line 2"}
for i = #lines, 1, -1 do
	local y = 480 - height - ((#lines - i + 1) * height)
	love.graphics.print(lines[i], 5, math.floor(y))
end
game.loadFont

Code: Select all

game = {}
function game.loadFont(fontPath, size)
	if (not game.fontCache[fontPath]) then
		game.fontCache[fontPath] = {}
	end
	
	if (not game.fontCache[fontPath][size]) then
		game.fontCache[fontPath][size] = love.graphics.newFont("files/fonts/"..fontPath, size)
		game.fontCache[fontPath][size]:setFilter("nearest", "nearest")
	end
	return game.fontCache[fontPath][size]
end
drawing the canvas

Code: Select all

love.graphics.setBlendMode('alpha', "premultiplied")
love.graphics.draw(staticCanvas, x, y, 0, w / defW, h / defH)
I've checked each variable, they're all integers, i can't seem to find out why the text gets blurred like on the screen.
I've also tried to change the filter from "nearest" to "linear", but that doesn't change anything at all!
What i've also tried is removing everything that changed the blendmode, but that didn't change anything either.

For anyone who wants to setup a demo, heres the font: http://www.fontpalace.com/font-details/Consolas/

Sorry for not giving out the .love file, it contains a few files that are private which i don't want to share, but i've pasted everything needed in this post, so you can just copy paste the snippets(mostly).

Anyone can help me figure this out?

Sincerely, nGear
Last edited by nGear on Fri Jun 24, 2016 9:07 pm, edited 1 time in total.
nGear
Prole
Posts: 3
Joined: Sun Apr 10, 2016 5:49 pm

Re: Fonts blurry on low pixel size when drawn onto canvas

Post by nGear »

I found out why!
The canvas was created with a dimension of {677, 343}
i have now changed the dimension to {678, 344} and now it's not blurry at all!
Honestly, i have no idea why this happens.
This seems to be a really weird issue that shouldn't be happening normally.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Fonts blurry on low pixel size when drawn onto canvas[SOLVED]

Post by pgimeno »

Hard to say without a complete example. Maybe you were drawing the canvas at non-integer coordinates.
nGear
Prole
Posts: 3
Joined: Sun Apr 10, 2016 5:49 pm

Re: Fonts blurry on low pixel size when drawn onto canvas[SOLVED]

Post by nGear »

Oh wow, yeah that was probably the case, i didn't think about that maybe being the case, i was too focused on the print, anyways as i've wrote i've fixed it now, thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 214 guests