Alternate to DrawPoly?

BlitzMax Forums/BlitzMax Programming/Alternate to DrawPoly?

I'm having some problems with the built-in DrawPoly method.. as you can see from the code example below, there is a large ugly white triangle (caused by overlapping polygons) that shouldn't be there.

Graphics 800, 600
SetBlend alphablend

While Not KeyHit( KEY_ESCAPE ) = True

	Cls
	Local poly:Float[] = [0.0, 200.0, 0.0, 0.0, 200.0, 0.0, 200.0, 100.0, 100.0, 100.0, 100.0, 200.0]
	SetOrigin 400, 300
	SetColor 255, 255, 255
	SetAlpha 0.5
	DrawPoly poly
	
	SetColor 255, 0, 0
	SetAlpha 1.0
	For i = 0 Until poly.length Step 2
		DrawOval poly[i] - 2, poly[i+1] - 2, 4, 4
	Next
	
	Flip

Wend
End


Does anyone have any alternatives to DrawPoly that produce more reliable results?

Thanks,
Chris

'====================================================================================================
'	File Name:	Type_TShapeBit.Bmx		
'----------------------------------------------------------------------------------------------------
'	Type Description:	So that I can have concave shapes a bit of a shape
'----------------------------------------------------------------------------------------------------
'	History
'	1.00	Created
'====================================================================================================
Type TShapeBit						'Bit of a shape
				'----------------------------------------------
	Field	F_PointsArray				:Float[]	
	Field	F_NumberOfPoints	:Int	
				'----------------------------------------------
Function RF_CreateFromArray:TShapeBit(P_Array:Float[])
		
	Local Temp	:TShapeBit = New TShapeBit.RM_SetFromArray(P_Array)
	Return Temp
		
End Function
				'----------------------------------------------
Function RF_CreateFromFloats:TShapeBit(P_X:Float,P_Y:Float)
	
	Local Temp:TShapeBit = New TShapeBit.RM_SetFromFloats(P_X,P_Y)
	Return Temp
	
End Function
				'----------------------------------------------		
Method RM_SetFromArray:TShapeBit(P_Array:Float[])
		
	F_PointsArray		= P_Array
	F_NumberOfPoints	= SizeOf(P_Array)/8
	Return Self		
	
End Method			
				'----------------------------------------------
Method RM_SetFromFloats:TShapeBit(P_X:Float,P_Y:Float)
	
	F_PointsArray				= New Float[2]
	F_PointsArray[0]		= P_X
	F_PointsArray[1]		= P_Y
	F_NumberOfPoints	= 1
	Return Self	
		
End Method
				'----------------------------------------------
Method SM_AddFloats (P_X:Float,P_Y:Float)
	
	F_NumberOfPoints:+ 1									
	F_PointsArray = F_PointsArray[ ..(F_NumberOfPoints * 2)]	
	F_PointsArray[(F_NumberOfPoints*2)-2] = P_X	
	F_PointsArray[(F_NumberOfPoints*2)-1] = P_Y
		
End Method
				'----------------------------------------------
Method DM_Draw ()
	
	DrawPoly F_PointsArray	
	
End Method
				'----------------------------------------------
Method SM_ReSizeFloats(P_MultiX:Float,P_MultiY:Float)
	
	For Local Loop:Int = 0 To (F_NumberOfPoints-1)*2 Step 2
		F_PointsArray[Loop]:*	P_MultiX
		F_PointsArray[Loop+1]:*	P_MultiY
	Next
	
End Method
				'----------------------------------------------
Method SM_Scale(P_Scale:Float)
	
	SM_ReSizeFloats(P_Scale,P_Scale)
	
End Method
				'----------------------------------------------
Method SM_FlipHoriz()
		
	For Local Loop:Int = 0 To (F_NumberOfPoints-1)*2 Step 2
		F_PointsArray[Loop+1]:* -1
	Next
		
End Method
				'----------------------------------------------
Method SM_FlipVert()
	
	For Local Loop:Int = 0 To (F_NumberOfPoints-1)*2 Step 2
		F_PointsArray[Loop]:*-1
	Next
		
End Method
				'----------------------------------------------
EndType
'====================================================================================================

'====================================================================================================
'	File Name:	Type_TShape.Bmx		
'----------------------------------------------------------------------------------------------------
'	Type Description:	Concave filled shape
'----------------------------------------------------------------------------------------------------
'	History
'	1.00	Created
'====================================================================================================
Type TShape							'Concave filled shape
	'------------------------------------------------------- 	
	Field	F_BitArray				:TShapeBit[]	
	Field	F_NumberOfBits	:Int		'	Number of Points in shape
				'----------------------------------------------
				
Function RF_CreateFromArray:TShape (P_Array:Float[])
		
	Local Temp:TShape = New TShape.RM_SetFromArray(P_Array)
	Return Temp
		
End Function
				'----------------------------------------------
Function RF_CreateFromFloats:TShape(P_X:Float,P_Y:Float)
	
	Local Temp:TShape = New TShape.RM_SetFromFloats(P_X,P_Y)
	Return Temp
		
End Function
				'----------------------------------------------
Method RM_SetFromArray:TShape (P_Array:Float[])
		
	Self.F_BitArray 		= New TShapeBit[1]
	Self.F_BitArray[0]		= TShapeBit.RF_CreateFromArray(P_Array)
	Self.F_NumberOfBits 	= 1	
	Return Self		
	
End Method
				'----------------------------------------------
Method RM_SetFromFloats:TShape(P_X:Int,P_Y:Int)
		
	Self.F_BitArray		= New TShapeBit[1]
	Self.F_BitArray[0]	= TShapeBit.RF_CreateFromFloats(P_X,P_Y)
	Self.F_NumberOfBits	= 1
		
End Method
				'----------------------------------------------
Method SM_NextPolyFloats(P_X:Int,P_Y:Int)
	
	Self.F_NumberOfBits:+1
	Self.F_BitArray = Self.F_BitArray[.. Self.F_NumberOfBits]
	Self.F_BitArray[Self.F_NumberOfBits-1] = TShapeBit.RF_CreateFromFloats(P_X,P_Y)
		
End Method
				'----------------------------------------------
Method SM_AddFloats (P_X:Int,P_Y:Int)
	
	Self.F_BitArray[Self.F_NumberOfBits-1].SM_AddFloats(P_X,P_Y)
		
End Method
				'----------------------------------------------
Method DM_Draw ()	
	
	For Local Loop:Int = 0 To Self.F_NumberOfBits-1 
		Self.F_BitArray[Loop].DM_Draw()
	Next
	
End Method
				'----------------------------------------------
Method SM_ReSizeFloats(P_X:Float,P_Y:Float)
		
	For Local Loop:Int = 0 To Self.F_NumberOfBits-1
		Self.F_BitArray[Loop].SM_ReSizeFloats(P_X,P_Y)
	Next
		
End Method
				'----------------------------------------------
Method SM_Scale(P_Multi:Float)
			
	For Local Loop:Int = 0 To Self.F_NumberOfBits-1
		Self.F_BitArray[Loop].SM_Scale(P_Multi)
	Next
		
End Method
				'----------------------------------------------
EndType
'====================================================================================================


Thanks for that H&K, I threw together a quick test to see if it works, but it seems to produce exactly the same results as DrawPoly().

In my main program, the points are plotted by clicking the mouse onto a grid, so any kind of wierd and wonderful shape could be created..

From looking at the code, it looks like the shape is split into smaller pieces, but it doesn't appear to be an automatic process. Any more information regarding the code above would be appreciated.

Thanks,
Chris

You have to split the poly into only convex parts. That is each shapebit should be convex.
Its totly useless for your auto thingy, as the bits need to be pre calculated