Thick Lines
BlitzMax Forums/BlitzMax Beginners Area/Thick Lines
| ||
Can I draw thick lines using DrawLine? SetScale doesn't make them thicker. |
| ||
could be wrong but don't think so, tryDrawRect(x1 , y1 , x2 , y2) |
| ||
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 |
| ||
The command you want is called SetLineWidth |
| ||
or that |
| ||
for Last edited 2011 |
| ||
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. |
| ||
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. |
| ||
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. |
| ||
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 |
| ||
Thanks for the suggestions! DrawLine with SetLineWidth worked perfectly though, I only wanted to draw a slightly thicker line :) |