module SetLinePattern() (should be in glmax2d)

BlitzMax Forums/BlitzMax Module Tweaks/module SetLinePattern() (should be in glmax2d)

skn3(Posted 2005) [#1]
Well this should be in the glmax2d module, but as it isn't, and until it is.. here is a module to change the pattern of lines drawn in bmax.

save as 'mod\skn3.mod\linepatterns.mod\linepatterns.bmx'
Strict

Module skn3.linepatterns

Import Pub.OpenGL

Private
	Global state_linestipple = False
	Global linestipple_pattern:Short
	Global linestipple_stretch:Int
Public

Rem
bbdoc: Set the drawing pattern for lines
about:
Allows you to set the pattern for drawn lines.<br><br>
Params:<br>
<b>pattern</b>:short<br>
This each bit in the short refers to a pixel on the line. 1 indicates the pixel is drawn 0 indicates it isn't drawn. 
You can pass a bit pattern like so %1111111100000000 this pattern would be 8pixels on 8 off, repeated.<br>
<b>stretch</b>:short (range 0-255)<br>
Allows you to stretch the pattern. 
End Rem
Function SetLinePattern(pattern,stretch=0)
	If stretch < 0 stretch = 0
	If stretch > 255 stretch = 255
		
	If pattern <> 0 And pattern <> 1
		If Not(state_linestipple)
			glEnable(GL_LINE_STIPPLE)
			state_linestipple = True
		End If
		glLineStipple(stretch,pattern)
	Else
		If state_linestipple
			glDisable(GL_LINE_STIPPLE)
			state_linestipple = False
		End If
	End If
	linestipple_pattern = pattern
	linestipple_stretch = stretch
End Function

Rem
bbdoc: Get the current drawing pattern for lines
End Rem
Function GetLinePattern(pattern:Short Var,stretch:Int Var)
	pattern = linestipple_pattern
	stretch = linestipple_stretch
End Function