Page 1 of 1

draw.circle

Posted: Thu Jun 02, 2011 7:21 pm
by bitlord
I was wondering why it still uses lines when the line width is not 1
I use something like this

Code: Select all

function generate_circle(mode,x, y, r, w, n, r1, r2)
	local cp = {}
	if r1 == nil then r1 = 0 end
	if r2 == nil then r2 = 2*math.pi end
	local t = (r2-r1)/n
	if mode == "inner" then
		r = r-w/2
	elseif mode == "outer" then
		r= r+w/2
	end
	for i=0,n,1 do
		cp[4*i + 1] = x + (r-w/2)*math.cos(r1+i*t)
		cp[4*i + 2] = y + (r-w/2)*math.sin(r1+i*t)
		cp[4*i + 3] = x + (r+w/2)*math.cos(r1+i*t)
		cp[4*i + 4] = y + (r+w/2)*math.sin(r1+i*t)
	end
	return cp
end


function draw_quadstrip(mode, q)
	for i=1,#q-4,4 do
		love.graphics.quad( mode, q[i], q[i+1], q[i+2], q[i+3],
			q[i+6], q[i+7], q[i+4], q[i+5] )
	end
end
mode : one of "inner" "outer" "mid" , direction in which the circle gains thickness
x, y : center
r : radius
w : width
n : segments
r1 : start angle(radian)
r2 : end angle(radian)
circle = generate_circle(...)
draw_quadstrip("fill", circle)

Re: draw.circle

Posted: Fri Jun 03, 2011 1:05 am
by Robin
bitlord wrote:I was wondering why it still uses lines when the line width is not 1
I'm sorry, what is your question?

Re: draw.circle

Posted: Fri Jun 03, 2011 6:47 am
by bitlord
It is obvious.

Code: Select all

function love.draw()
 love.graphics.setLineWidth(30)
 love.graphics.circle( "line", 200, 200, 100, 10)
end
result:
a4TRZ.png
a4TRZ.png (1.69 KiB) Viewed 810 times

Re: draw.circle

Posted: Fri Jun 03, 2011 7:14 am
by BlackBulletIV
Ramp up that last parameters to love.graphics.circle. You might want something like 50 or so. The greater the number the more detailed the circle (and the more costly to performance, so be weary of drawing circles).

Re: draw.circle

Posted: Fri Jun 03, 2011 7:36 am
by bitlord
but it doesn't matter since it is composed of separate lines
so you will always have artifacts

Re: draw.circle

Posted: Fri Jun 03, 2011 10:39 am
by bitlord
example of what I mean

Re: draw.circle

Posted: Fri Jun 03, 2011 10:42 am
by vrld
Lines and OpenGL dont play very well together. However, this will be gone in love 0.8.