Thick Lines

BlitzMax Forums/BlitzMax Beginners Area/Thick Lines

Czar Flavius(Posted 2011) [#1]
Can I draw thick lines using DrawLine? SetScale doesn't make them thicker.


InvisibleKid(Posted 2011) [#2]
could be wrong but don't think so, try
DrawRect(x1 , y1 , x2 , y2)



Perturbatio(Posted 2011) [#3]
SetGraphicsDriver GLMax2DDriver()
Graphics 800, 600

Global linewidth:Float = 5.0

glLineWidth(lineWidth)


While Not KeyDown(KEY_ESCAPE) Or AppTerminate()
	Cls
	
	DrawLine(400, 300, MouseX(), MouseY())
	
	Local zspeed:Int = MouseZSpeed()
	
	If (zspeed <> 0) Then
		
		lineWidth :+ Min(10.0, Max(0.1, (0.1*zspeed)))
		
		
		glLineWidth(lineWidth)
	End If
	
	Flip
Wend
End





Warpy(Posted 2011) [#4]
The command you want is called SetLineWidth


Perturbatio(Posted 2011) [#5]
or that


Jesse(Posted 2011) [#6]
for DX Max2d scaling purpose DrawRect is the best option. SetLineWidth has a limit between 5 and 10 not sure how much although for centering the line you would have to figure it out through some trig magic. not too difficult for you I am sure.

Last edited 2011


Czar Flavius(Posted 2011) [#7]
SetLineWidth has done the trick, thanks! I didn't even know this command existed. I couldn't use rectangles because the lines are at any angle.


Jesse(Posted 2011) [#8]
It can be done with DrawRect but a bit more work needed to for the same result. As long as you don't need to set the line width wider than the max then SetLineWidth would be the best option. For me I had to use drawRect and calculate the center of the width of the line to draw it accurately in place.


ImaginaryHuman(Posted 2011) [#9]
If you are using OpenGL I recommend switching on glEnable(GL_LINE_SMOOTH) and draw your lines in LIGHTBLEND more or similar, to draw antialiased lines.


Warpy(Posted 2011) [#10]
The DrawRect approach involves using SetRotation. It's better to use DrawRect for really thick lines, because bmax's DrawLine doesn't quite look right when drawn at an angle.

Run this code to see what I mean:
Graphics 600,600,0

an=0
x1=300
y1=300
While Not (KeyHit(KEY_ESCAPE) Or AppTerminate())
	an:+1
	
	x2#=x1+Cos(an)*100
	y2#=y1+Sin(an)*100
	
	SetColor 255,255,255
	drawthickline x1-50,y1,x2-50,y2,30	'draw a rotated rect
	
	SetLineWidth 30
	DrawLine x1+50,y1,x2+50,y2			'use bmax's built-in line drawing function
	
	SetColor 255,0,0
	SetLineWidth 1
	DrawLine x1-50,y1,x2-50,y2			'draw thin reference lines to show line is being drawn correctly
	DrawLine x1+50,y1,x2+50,y2

	Flip
	Cls
Wend

Function DrawThickLine(x1#,y1#,x2#,y2#,thickness#)
	rot#=GetRotation()
	dx# = x2-x1
	dy# = y2-y1
	length# = Sqr(dx*dx+dy*dy)
	an# = ATan2(dy,dx)
	SetRotation an
	DrawRect x1+Sin(an)*thickness/2,y1-Cos(an)*thickness/2,length,thickness
	SetRotation rot
End Function



Czar Flavius(Posted 2011) [#11]
Thanks for the suggestions!

DrawLine with SetLineWidth worked perfectly though, I only wanted to draw a slightly thicker line :)