Page 2 of 2

Re: Function to outline texts

Posted: Thu Nov 17, 2022 5:47 pm
by Gunroar:Cannon()
No, but this works a little for me, when I make it letter for letter.

Code: Select all


local op = love.graphics.print

function love.graphics.print(texty, x, y, ang, sx, sy, ...)
    if NO_DOUBLE_TEXT then
        return op(texty, x, y, ang, sy, sx, ...)
    end
    
    sx = sx or 1
    sy = sy or 1
    local font = love.graphics.getFont()
    
    for xx = 1, #texty do
        local text = texty:sub(xx,xx)
        local x = x+(xx~=1 and font:getWidth(texty:sub(1,xx-1)) or 0)*sx
        local r,g,b,a = love.graphics.getColor()
        love.graphics.setColor(0,0,0,a)--getColor(coloyr or "green",a))
    
        local scale = 1.1
        local nsx, nsy = (sx or 1)*scale, (sy or 1)*scale
    
        local diffX =(nsx - (sx or 1))/2
        local diffY = (nsy - (sy or 1))/2
    
        op(text, x-diffX, y-diffY, ang, nsx, nsy, ...)
        love.graphics.setColor(r,g,b,a)
        op(text, x, y, ang, sx, sy, ...)
    end
end

Re: Function to outline texts

Posted: Thu Nov 17, 2022 6:05 pm
by pgimeno
Gunroar:Cannon() wrote: Thu Nov 17, 2022 7:51 am Any way to fix it so it runs on both?
Maybe moving these two lines:

Code: Select all

vec2 q1 = quad.xy;
vec2 q2 = quad.xy + quad.zw;
to the beginning of the effect() function.

Re: Function to outline texts

Posted: Fri Nov 18, 2022 7:10 am
by Gunroar:Cannon()
Okay, yes. Now it works. But now I'm curious which takes more CPU, my version or your shader version?

Re: Function to outline texts

Posted: Fri Nov 18, 2022 8:18 am
by MrFariator
If I had to wager a random guess at a glance, I think your version is heavier on the CPU (due to the string.sub calls), because shader stuff happens more on the GPU. If you're worried about performance, just profile the two, and see if there's any discernible difference. In a case like this I don't think either's performance will be too heavy if you just need the occasional text box.

Re: Function to outline texts

Posted: Fri Nov 18, 2022 8:27 am
by darkfrei
But you can render the text and keep it as a canvas before you need to update it.
Actually you can pre-render the font and use the font sprites with any outlines for it.

Re: Function to outline texts

Posted: Fri Nov 18, 2022 7:00 pm
by Gunroar:Cannon()
OK, in performance overall it doesn't really .after (though there's a lot of UI text ). Thanks.
darkfrei wrote: Fri Nov 18, 2022 8:27 am But you can render the text and keep it as a canvas before you need to update it.
Actually you can pre-render the font and use the font sprites with any outlines for it.
Wow, that seems like the least heavy option, though more work for a simple thing ^^

Re: Function to outline texts

Posted: Fri Nov 18, 2022 9:48 pm
by darkfrei
Yes, the freebie is not free :)
You are need to pay for any optimization.

Re: Function to outline texts

Posted: Sat Nov 19, 2022 5:01 pm
by Gunroar:Cannon()
:rofl: