Anti-Tearing
Übersicht
BlitzBasic
Codearchiv
|
Ehemaliger Admin
Betreff: Anti-Tearing
|
Mi, Dez 01, 2004 9:58
Antworten mit Zitat
|
Nachdem Walski uns ein sehr unschönes beispiel gezeigt hat,https://www.blitzforum.de/viewtopic.php?t=7549, habe ich mal was dagegen gemacht.
Es ist nicht 100%ig aber doch schon eine Ganz gute lösung:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
Const screen_mode_fullscreen = 1 Const screen_mode_windowed = 2
Const screen_width = 800 Const screen_height = 600 Const screen_depth = 32 Const screen_mode = screen_mode_windowed
Global fps_last_time Global fps_counter Global fps_fps Global fps_interval
fps_interval = 100
Local vSync Local timer Local fBrake Local blockX
vSync = False
timer = CreateTimer( 70 )
fBrake = False
Graphics screen_width,screen_height,screen_depth,screen_mode SetBuffer BackBuffer()
Set_Monitor_HZ()
MonHZ = get_Monitor_HZ()
While Not KeyHit( 1 )
If KeyHit( 57 ) Then
If vSync Then
vSync = False
Else
vSync = True
EndIf
EndIf
If KeyHit( 14 ) Then
If fBrake Then
fBrake = False
Else
fBrake = True
EndIf
EndIf
If fBrake Then
WaitTimer( timer )
EndIf
handleFPS()
blockX = blockX + 5
Cls
handleBG( blockX )
Text 1,1,\"FPS: \" + fps_fps Text 1,20,\"vSync: \" + vSync Text 1,40,\"Frame-Brake: \" + fBrake Text 1,60,\"Monitor HZ: \" + MonHZ Flip_Buffers(vSync)
Wend
Global MonitorHZ%,TB_Time%,TB_UpdateTime#
Function Set_Monitor_HZ(HZ%=-1) If HZ% = -1 Then HZ=Get_Monitor_HZ%() MonitorHZ%=HZ%
TB_UpdateTime# = 1000.0/MonitorHZ% End Function
Function Flip_Buffers(VSyncWait%=0) Local Time% Time%=MilliSecs()
If VSyncWait% Then Repeat Time%=MilliSecs() Until Time% > TB_Time% + TB_UpdateTime# EndIf If Time% > TB_Time% + TB_UpdateTime# Then TB_Time%=Time% Flip 1 Return 1 EndIf Return 0 End Function
Function Get_Monitor_HZ%(Graphicsmode%=1) Local Sclline% Local Sclcount% Local SCLAkt% Local SCLgh%
SCLgh% = apiGetSystemMetrics(1)
Local t1% Local t2%
Local Mon_HZ%
Delay 2 T1=MilliSecs() SCLLine=ScanLine() Repeat SCLAkt%=ScanLine() If SCLAkt% < SCLLine Then SCLAkt%=SCLAkt%+SCLgh% SCLCount= SCLCount+SCLAkt%-SCLLine% SCLLine=SCLAkt%
Until SCLCount > SCLgh% t2=MilliSecs()
Mon_HZ% = 1000.0/Float(Float(t2-t1)*Float(SCLgh)/Float(SCLCount))
Return Mon_HZ% End Function
Function handleFPS()
Local tSecs
tSecs = MilliSecs() If tSecs > fps_last_time + fps_interval Then
fps_fps = Int( Float( fps_counter ) * ( 1000.0 / fps_interval ) )
fps_counter = 0
fps_last_time = tSecs
Else
fps_counter = fps_counter + 1
EndIf
End Function
Function handleBG( curX )
Local tX
tX = ( curX Mod screen_width ) * -1
For i = tX To screen_width - tX Step 50
Rect i,0,5,screen_height,1
Next
End Function
|
between angels and insects
|
Übersicht
BlitzBasic
Codearchiv
Powered by phpBB © 2001 - 2006, phpBB Group