Blitz3D+ Command Reference

VSync [enable]

Parameters

enable (optional) - True waits for the display refresh, False presents immediately; True (default)

Description

Synchronises Flip with the display refresh to avoid tearing.

With VSync on - the default - each Flip waits for the vertical blank, so frames never tear and the frame rate tops out at the monitor's refresh rate. That is the right choice for almost every finished game.

Turn it off to measure real performance while profiling, or when you want the lowest possible input latency and can accept visible tearing. With VSync off, consider FrameLimit so the game does not spin at thousands of frames per second on menus, heating up laptops for nothing.

For the full story, see the image-quality guide.

Requires Extended mode.

See also: FrameLimit, Flip.

Example

; 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

Index