`jGfx Plugin: GInst Example - Basic usage
`=============================================================================
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 (size of GInstBuffer)
bUseCulling = 1			`True to enable GInstBuffer culling
bUseNormalMapping = 1	`True if normal mapping should be used


`Setup Instance Source Object
ObjectID = 1
Make Object Sphere 1, 50, 12, 24
Convert Object FVF 1, 0x002 || 0x010 || 0x100
Load Image "Media\bricks.png", 1
Texture Object ObjectID, 0, 1 `note: set render mesh textures before applying to GInst

If bUseNormalMapping
	`apply normalmap texture
	Load Image "Media\bricks_n.png", 2
	Texture Object ObjectID, 1, 2
	`load GInst compatible normalmapping effect
	Load Effect "Media\GInst_Normal.fx", 1, 0
Else
	`load GInst compatible diffuse effect
	Load Effect "Media\GInst_Diffuse.fx", 1, 0
Endif



`Create new GInst to use as a source for instance render data
pGInst = GInst_MakeNew()
`Setup the GInst's meshlist using the object's limbs
GInst_SetObject pGInst, ObjectID
`Apply effect
GInst_SetEffect pGInst, 1



`Create a GInstBuffer
pInstBuffer = GInstBuffer_MakeNew( pGInst, InstanceCount )
`Setup culling (enabled by default)
GInstBuffer_SetCullingEnabled pInstBuffer, bUseCulling

`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_SetRotation pInstBuffer, i, Rnd(360), Rnd(360), Rnd(360)
	GInstBuffer_SetScale pInstBuffer, i, 100.0, 100.0, 100.0
	
	`Update the instance's world matrix
	GInstBuffer_UpdateInstance pInstBuffer, i
Next i

`Update the instance stream to contain the latest instance data
GInstBuffer_Update pInstBuffer, bUseCulling `only need to update bounds if culling is enabled





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
