Function to outline texts

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Function to outline texts

Post 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
Attachments
New version
New version
Screenshot_2022-11-17-18-45-32.png (175.51 KiB) Viewed 1498 times
Multiprint Test
Multiprint Test
Screenshot_2022-11-17-18-42-46.png (21.36 KiB) Viewed 1498 times
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Function to outline texts

Post 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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Function to outline texts

Post by Gunroar:Cannon() »

Okay, yes. Now it works. But now I'm curious which takes more CPU, my version or your shader version?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Function to outline texts

Post 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.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Function to outline texts

Post 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Function to outline texts

Post 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 ^^
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Function to outline texts

Post by darkfrei »

Yes, the freebie is not free :)
You are need to pay for any optimization.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Function to outline texts

Post by Gunroar:Cannon() »

:rofl:
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 50 guests