; VSync Example ; ------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-7 RotateEntity camera,10,0,0 light=CreateLight() RotateEntity light,45,45,0 ; A fast-spinning striped drum; tearing shows on it when VSync is off drum=CreateCylinder() ScaleEntity drum,1.5,2,1.5 PositionEntity drum,0,2,2 EntityColor drum,240,200,60 post=CreateCube() ScaleEntity post,0.3,2,0.3 PositionEntity post,0,0,2 EntityColor post,120,160,220 sync=1 frames=0 fps=0 timer=MilliSecs() While Not KeyDown(1) ; Press Space to toggle vertical synchronisation If KeyHit(57) Then sync=1-sync ; Synchronise Flip with the display, or present immediately VSync sync ; Count real frames per second frames=frames+1 If MilliSecs()-timer>=1000 Then fps=frames frames=0 timer=MilliSecs() EndIf TurnEntity drum,0,7,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: toggle VSync Arrow keys: move camera Esc: exit" If sync Text 0,20,"VSync True (Flip waits for the display - no tearing)" Else Text 0,20,"VSync False (Flip presents immediately)" EndIf Text 0,40,"Measured: "+fps+" fps" Flip Wend End