Best way to draw a rounded-corner square image with borders?

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
bitinn
Prole
Posts: 8
Joined: Sun Apr 10, 2016 9:44 am

Best way to draw a rounded-corner square image with borders?

Post by bitinn »

What's the best approach to drawing a square image with borders and rounded-corners.

To give an example, from this:
Screen Shot 2016-04-10 at 6.02.25 PM.png
Screen Shot 2016-04-10 at 6.02.25 PM.png (30.1 KiB) Viewed 3208 times
To this:
Screen Shot 2016-04-10 at 6.02.34 PM.png
Screen Shot 2016-04-10 at 6.02.34 PM.png (27.37 KiB) Viewed 3208 times
My first thought are line mode rectangle with radius on top of the image, but what about the image itself, how can I mask / clip the image with a rounded-corner square efficiently. I don't need a mesh here, do I?

PS: this is my post here, let me know if I am missing any forum rules :)
User avatar
pgimeno
Party member
Posts: 3641
Joined: Sun Oct 18, 2015 2:58 pm

Re: Best way to draw a rounded-corner square image with borders?

Post by pgimeno »

If the border is thick enough, the corner will be hidden. In your case it is:

Image

So, the most efficient way is probably to draw the image (with a size smaller than the rounded rect) and the rounded rect over it.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Best way to draw a rounded-corner square image with borders?

Post by s-ol »

and otherwise, you can use a stencstencil function to do the clipping. I would advise to make the stencil a bit smaller than the border also though, so you don't end up with any weird edges.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
bitinn
Prole
Posts: 8
Joined: Sun Apr 10, 2016 9:44 am

Re: Best way to draw a rounded-corner square image with borders?

Post by bitinn »

Thx folks, stencil is what I want.
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Best way to draw a rounded-corner square image with borders?

Post by Manyrio »

For border you can use GLSL shaders
function love.load() end
function love.update(dt) end
function love.draw() end
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests