#HTML5_CANVAS_ANTIALIAS=False
#GLFW_WINDOW_FULLSCREEN = True
#GLFW_WINDOW_RESIZABLE = True
#GLFW_WINDOW_RENDER_WHILE_RESIZING = True
#MOJO_AUTO_SUSPEND_ENABLED=False
Import mojo2
Function Main ()
New Game
Return 0
End
Class Game Extends App
Field vertices:Float[]
Field vertcol:Int[]
Field indices:Int[]
Field canvas:Canvas
Method OnCreate ()
canvas=New Canvas
' Define some polygons
vertices=New Float[4*2*1000]
vertcol=New Int[4*2*1000]
Local sz:=80.0,p:=0
For Local i:=0 Until 1000
Local x:=Rnd(DeviceWidth)-sz/2-DeviceWidth/2
Local y:=Rnd(DeviceHeight)-sz/2-DeviceHeight/2
vertices[p+0]=x
vertices[p+1]=y
vertices[p+2]=x+sz
vertices[p+3]=y
vertices[p+4]=x+sz
vertices[p+5]=y+sz
vertices[p+6]=x
vertices[p+7]=y+sz
' Set polygon color
Local c:Int ' Purple
c = PremultiplyColors(1.0,0.0,1.0,1.0) ' r,g,b,a
vertcol[p+0] = c
vertcol[p+1] = c
vertcol[p+2] = c
vertcol[p+3] = c
vertcol[p+4] = c
vertcol[p+5] = c
vertcol[p+6] = c
vertcol[p+7] = c
' Set some polygons to another color
If Rnd(1) > 0.5
' Yellow
c = PremultiplyColors(1.0,1.0,0.0,1.0)
vertcol[p+0] = 65535 ' c works fine but 65535 gives a weird overlap white effect
vertcol[p+1] = 65535 '
vertcol[p+2] = 65535 '
vertcol[p+3] = 65535 '
vertcol[p+4] = 65535 '
vertcol[p+5] = 65535 '
vertcol[p+6] = 65535 '
vertcol[p+7] = 65535 '
Endif
p+=8
Next
indices=New Int[4000]
For Local i:=0 Until 4000
indices[i]=i
Next
End
Method OnRender : Int()
canvas.Clear
' DRAW POLYGONS
canvas.SetColor 1,0,0
For Local i:Int = 0 Until vertices.Length()
vertices[i] += Rnd(-1.25, 1.25)
Next
' API Reference
' DrawPrimitives : Void ( order:Int, count:Int, vertices:Float[], texcoords:Float[], vertcols:Int[] )
' DrawPrimitives : Void ( order:Int, count:Int, vertices:Float[])
' canvas.DrawPrimitives 4,100,vertices ' one color (works)
canvas.DrawPrimitives 4,100,vertices,vertices,vertcol ' Multicolor (works but weird (texcoords is not interesting bt you need the parameter)
' canvas.DrawPrimitives 4,100,vertices,,vertcol ' Multicolor (does now work)
canvas.Flush
Return 0
End
Function PremultiplyColors:Int(r:Float, g:Float, b:Float, a:Float)
a *= 255
Return Int(a) Shl 24 | Int(b * a) Shl 16 | Int(g * a) Shl 8 | Int(r * a)
End
End