monkey2 icon indicating copy to clipboard operation
monkey2 copied to clipboard

Color.ToARGB is wrong format for DrawPrimitives()

Open Difference opened this issue 8 years ago • 1 comments

I made a small program to show why I think the docs, the code or both are wrong, as I first discovered here: #157

I think docs should be corrected to say ABGR and a Color.ToABGR() added OR DrawPrimitives should be changed to take ABGR Uints.

#Import "<std>"
#Import "<mojo>"
 
Using std..
Using mojo..
 
Class MyWindow Extends Window
	
	Field poly:= New Float[8]
	Field colors:= New Uint[4]
 
	Method New()
		
		Local x:Float = 100
		Local y:Float = 100
		Local w:Float = 400
		Local h:Float = 300
 
		poly[0]=x
		poly[1]=y		
		poly[2]=x+w
		poly[3]=y		
		poly[4]=x+w
		poly[5]=y+h
		poly[6]=x
		poly[7]=y+h
 
		Local col:UInt = Color.Red.ToARGB()	' results red blue inverted when used in DrawPrimitives()	
		'Local col:UInt = ToABGR(Color.Red)	' need this for correct colors for DrawPrimitives()
 
		colors[0]=col
		colors[1]=col		
		colors[2]=col
		colors[3]=col
 	
	End Method
		
	Method OnRender( canvas:Canvas ) Override
		App.RequestRender()
	
		canvas.DrawPrimitives(4,1,poly.Data,8,Null,0,colors.Data,4,null,null )		
		
	End
	
End
 
	Function ToABGR:UInt(c:Color)
		Return UInt(c.a*255) Shl 24 | UInt(c.b*255) Shl 16 | UInt(c.g*255) Shl 8 | UInt(c.r*255)
	End Function	
 
 
Function Main()
	New AppInstance
	New MyWindow
	
	App.Run()
End

Difference avatar Apr 06 '17 07:04 Difference

'ToABGR' method added to std.Color class (e318d2a). This issue can be closed.

seyhajin avatar Jun 04 '19 10:06 seyhajin