ScreenVSync
ScreenVSync Flag
 
Parameters:

    Flag = Vsync State (1 = Enable) (0 = off)
Returns: NONE
 

     ScreenVSync enables/disables vertical beam synchronization during for screen refresh. When enabled this makes the SYNC command refresh the screen to your monitor using your graphics cards vertical beam. This gives smoother graphics refresh, at the expensive of some performance !




FACTS:


      * ScreenVSync is off by default.

      * ScreenVSync is supported in both window and full screen modes.

      * When ScreenVSync is enabled, you get smoother graphics refresh, but slower (often fixed) frame rates !

      * Since enabling VSync makes your program refresh at the monitors refresh rate. Don't assume that other peoples computers will run at the same refresh rate as yours. Their monitor refresh could be set higher/lower than yours! So in those cases, your game with run faster or slower on such computers.

      * ScreenVSync is a frame limiting mechanism. Therefore, it does not tween the frame rate of your application. So if the machine your program is running upon isn't fast enough to meet your required frame rate, the program will slow down. There's a number of strategies to coupe with this, one common one is something called Timer Based Movement. There's a number of timer based movement examples on the forums as well as the bare bones example bellow and on the timer page.


      * It's not recommended to use the ScreenVSync in conjunction with SetFPS. This tends to make the frame rate choppy. If you do, we recommend setting the preferred frame rate to say 100 or 200. This is unlike to impact on the Vsync control and should prevent your program from being a complete system hog on machines that either don't have a Vsync support, or it's disabled.


Important Note:

     Many video card drivers, allow the end users to override vertical beam synchronization. Therefore, users who disable VYSNC in their video drivers, won't see any affect by enabling ScreenVSync on those machines, nor will turning on Vsync slow your program down on these machines.

      Therefore, it's wise to implement object movements independent of the computers actual frame rate.




Example #1:


      This simple example creates a screen, enables Vsyncing, then renders some coloured scrolling boxes to the screen. While the example runs the user enable/disable Vsyncing to view the effect on the smoothness of the scrolling output.

  
; open the screen in full 800x * 600Y, 16bit  mode
  OpenScreen 800,600,16,2
  
; Enable Sync'ing against the vertical beam
; This gives smoother GFX refresh, but slower updates
  ScreenVsync on
  
; Start a Do/Loop
  Do
   ; Clear the screen
     Cls RGB(0,0,0)
     
     w=40
     h=GetScreenHeight()
     t=ScrollTog
     For xlp=-To GetScreenWidth() Step w
      ;  Toggle the T value
        t=Not t
      ; if T is TRUE (equal to 1)
        If t
         ; Draw a Box
           BoxC x+xlp,ylp,x+xlp+w,h,1,RGB(255,255,0)
        EndIf
     Next
     
   ; Increase the X offset variable
     x=x+2
     
   ; if the X offset bigger than the block width,
   ; then reset it.
     If x>w
        x=Mod(x,w)
        ScrollTog = Not scrolltog
     EndIf
     
   ; Display a message about the controls
     Print "Press Space to Toggle VSync"
     Print GetScreenVsync()
     
   ; Check if the SPace Key Was pressed
     If SpaceKey()=true
        
      ; Toggle the Current Screen V Sync mode
        ScreenVsync Not GetScreenVsync()
        
      ; flush all key input
        FlushKeys
     EndIf
     
     Sync
  Loop
  




Example #2 -Timer Based Movement:


      This example moves a circle LEFT to RIGHT across the screen. Rather than using frame based movement, where we'd normally add our movement speed onto the moving object each time through the main loop, this time we're using Timer Based Movement.


      You can toggle VSYNC using the SPACE BAR.

  
  
; open the screen in full 800x * 600Y, 16bit  mode
  OpenScreen 800,600,16,2
  
; Enable Sync'ing against the vertical beam
; This gives smoother GFX refresh, but slower updates
  ScreenVsync on
  
  
; Get the Starting Time of this program
  StartTime = Timer()
  
  
  
; Start a Do/Loop
  Do
   ; Clear the screen
     Cls RGB(0,0,0)
     
     
     
   ; Calc the number of milliseconds have passed since
   ; the program started
     TimePast=Timer()-StartTime
     
   ; Calc the position of the moving circle,
   ;
   ; Here we want our object to move 300 pixels
   ; every second.
     
     PixelsPerMilliSecond#=(300.0/1000.0)
     
   ; Calc it's position after this much time
     Xpos# = TimePast * PixelsPerMilliSecond#
     
   ; wrap it within the screen width
     Xpos#=Mod(Xpos#,800)
     
   ; draw a circle to represent this object
     Circle Xpos#,300,30
     
     
   ; Display a message about the controls
     Print "Press Space to Toggle VSync"
     Print GetScreenVsync()
     
   ; Check if the SPace Key Was pressed
     If SpaceKey()=true
        
      ; Toggle the Current Screen V Sync mode
        ScreenVsync Not GetScreenVsync()
        
      ; flush all key input
        FlushKeys
     EndIf
     
     Sync
  Loop
  
  



 
Related Info: GetScreenVSync | OpenScreen | SetFPS | SwapScreen | Sync | Timer :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com