love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
5k stars 397 forks source link

Drawing a canvas with text leads to blurry, shadowed text #2094

Closed therainingmonkey closed 1 month ago

therainingmonkey commented 2 months ago

Changing filter to 'nearest' doesn't appear to make a difference. The effect holds at different font sizes and different fg/bg color combinations.

Here I've drawn white text on a white background to highlight the shadows: Screenshot_2024-08-21_1

Here is the code to reproduce:

function love.load()
    canvas = love.graphics.newCanvas()
    font = love.graphics.newFont(48)
    love.graphics.setFont(font)

    love.graphics.setBackgroundColor(1,1,1)
end

function love.draw()
    love.graphics.setCanvas(canvas)
        love.graphics.clear()
        love.graphics.print('Lauren Ipsem was a very naughty girl', 20, 50)

    love.graphics.setCanvas()
    love.graphics.draw(canvas)

    love.graphics.print('The quick brown fox ran into the city', 20, 100)
end
erinmaus commented 2 months ago

This isn't a bug, you need to draw your canvas with a premultiplied alpha blending mode.

function love.load()
    canvas = love.graphics.newCanvas()
    font = love.graphics.newFont(48)
    love.graphics.setFont(font)

    love.graphics.setBackgroundColor(1,1,1)
end

function love.draw()
    love.graphics.setCanvas(canvas)
    love.graphics.clear()
    love.graphics.print('Lauren Ipsem was a very naughty girl', 20, 50)

    love.graphics.setCanvas()
    love.graphics.setBlendMode("alpha", "premultiplied")
    love.graphics.draw(canvas)

    love.graphics.setBlendMode("alpha", "alphamultiply")
    love.graphics.print('The quick brown fox ran into the city', 20, 100)
end