''
'' pgflip.bas -- page flipping ex
''

DefInt a-z
'$Include: '..\inc\ugl.bi'

Const xRes = 320*2
Const yRes = 200*2
Const cFmt = UGL.8BIT

Declare Sub ExitError (msg As String)

'':::
    Dim video As Long
    
    '' initialize
    If (not uglInit) Then ExitError "Init"
    
    '' change video-mode
    video = uglSetVideoDC(cFmt, xRes, yRes, 2)
    If (video = 0) Then ExitError "SetVideoDC"
    
    visPg = 0
    wrkPg = 1
    
    colors& = uglColors(cFmt)
    iTmr# = timer
    Do                
        uglSetVisPage visPg
        '' wait for vertical-sync
        Do: Loop Until ( inp(&h3DA) and &h08 )
        uglSetWrkPage wrkPg

        Swap visPg, wrkPg               '' vis=wrk | wrk=vis

        uglClear video, 0
        For i = 1 To 10
            uglRectF video, Rnd * xRes, Rnd * yRes, _
                            Rnd * xRes, Rnd * yRes, _
                            Rnd * colors&
        Next i
        
        fps& = fps& + 1
    Loop While (Inkey$ = "")
    eTmr# = timer
    
    uglRestore
    uglEnd
    print "fps:"; Clng(fps& / (eTmr#-iTmr#))
    End

'':::
Sub ExitError (msg As String)
    uglRestore
    uglEnd
    Print "ERROR! "; msg
    End
End Sub
