`jGfx Plugin: GInst Example - Multi mesh instance rendering
`==================================================================
Sw = Desktop Width()
Sh = Desktop Height()
Set Display Mode Sw,Sh,32,1
Sync On : Sync Rate 0
Color Backdrop 0
Autocam Off


`Example Settings
InstanceCount = 100		`Number of instances to create




`Create a multi-mesh source object
ObjectID = 1
Make Object Cube ObjectID, 50			`Limb0

TmpObj=2 : TmpMesh=1
Make Object Sphere TmpObj, 50, 8, 16	`Limb1
Offset Limb TmpObj, 0, 0.0, 50.0, 0.0
Make Mesh From Object TmpMesh, TmpObj
Delete Object TmpObj
Add Limb ObjectID, 1, TmpMesh	
Delete Mesh TmpMesh

Convert Object FVF ObjectID, 0x002 || 0x010 || 0x100 `XYZ + Normals + Tex1
Load Image "Media\bricks.png", 1
Load Image "Media\wall1.dds", 2
Texture Limb ObjectID, 0, 0, 1
Texture Limb ObjectID, 1, 0, 2


`load GInst compatible diffuse effect
Load Effect "Media\GInst_Diffuse.fx", 1, 0


`Create new GInst (used as a template for instance rendering)
pGInst = GInst_MakeNew()
`Setup the GInst's meshlist using the object's limbs
GInst_SetObject pGInst, ObjectID `Note: Textures must be applied before calling this command
`Apply Effect
GInst_SetEffect pGInst, 1


`Create a GInstBuffer to render instances from the GInst
pInstBuffer = GInstBuffer_MakeNew( pGInst, InstanceCount )

`Setup Instances
For i=1 To InstanceCount
	`Set random transforms
	PosX=Rnd(1000)-500
	PosZ=Rnd(1000)-500
	GInstBuffer_SetPosition pInstBuffer, i, PosX, 0.0, PosZ
	GInstBuffer_SetScale pInstBuffer, i, 100.0, 100.0, 100.0
	`Update the instance's world matrix
	GInstBuffer_UpdateInstance pInstBuffer, i
Next i

`Update instance stream
GInstBuffer_Update pInstBuffer





Position Camera -600, 150, -600
Rotate Camera 25, 45, 0

TimeSpeed# = 0.5
LastTime = Timer()
Do
	Set Cursor 0,0
	Print "FPS = ",Screen Fps()
	Print "Use the mouse and arrowkeys to control the camera"
	
	Now=Timer()
	TimePassed# = (Now-LastTime)*TimeSpeed#
	LastTime = Now

	Move Camera (UpKey()-DownKey())*TimePassed#
	Move Camera Right (RightKey()-LeftKey())*TimePassed#
	Rotate Camera Wrapvalue(Camera Angle X()+MouseMoveY()),  Wrapvalue(Camera Angle Y()+MouseMoveX()), 0

	Sync
Loop
