It is currently Tue Jan 26, 2021 8:53 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Is possible wait for vertical blanking on windows?
PostPosted: Sun Mar 15, 2020 12:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 22, 2016 5:33 pm
Posts: 139
Location: Spain
I'm an old school coder (Amiga rulez! 8) ) so... my question is:
Exists a vertical blank variable accessible to the user while in normal Windows (windowed)?


Top
 Profile  
Reply with quote  
 Post subject: Re: Is possible wait for vertical blanking on windows?
PostPosted: Sun Mar 15, 2020 12:55 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 805
Caronte3D wrote:
I'm an old school coder (Amiga rulez! 8) ) so... my question is:
Exists a vertical blank variable accessible to the user while in normal Windows (windowed)?


U can use OpenWindowScreen() with either #PB_Screen_WaitSynchronization or #PB_Screen_SmartSynchronization.
(Opengl (if used directly) also has functions to enable vSync -> ex. wglSwapIntervalEXT() on Windows.)
Anyhow you will need additional timing on top of that since monitors may have different refresh rates.


Top
 Profile  
Reply with quote  
 Post subject: Re: Is possible wait for vertical blanking on windows?
PostPosted: Sun Mar 15, 2020 1:48 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 22, 2016 5:33 pm
Posts: 139
Location: Spain
Thanks, Mijikai, but I hope (workaround?) something to use with "OpenWindow" can be done :?


Top
 Profile  
Reply with quote  
 Post subject: Re: Is possible wait for vertical blanking on windows?
PostPosted: Sun Mar 15, 2020 2:18 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 805
The other option would be a timer to render at fixed intervals.
Tearing is not really a problem, its not uncommon to see games that have options to disable vSync.

Edit: Just had an idea (old ddraw!) and it worked - have fun :)

Code:
Code:
;TINY VSYNC (DDRAW)
;AUTHOR: MIJIKAI

EnableExplicit

Procedure.i WaitForVerticalBlank();wait for vsync! / returns 1 on sucess 0 on failure / note: busy wait!
  Static *ddraw.IDirectDraw
  If Not *ddraw
    If DirectDrawCreate_(#Null,@*ddraw,#Null) = #Null
      If *ddraw\WaitForVerticalBlank($4,#Null) = #Null
        ProcedureReturn 1 
      Else
        ProcedureReturn 0
      EndIf
    Else
      ProcedureReturn 0
    EndIf
  Else
    If *ddraw\WaitForVerticalBlank($4,#Null) = #Null
      ProcedureReturn 1 
    Else
      ProcedureReturn 0
    EndIf
  EndIf
EndProcedure

Procedure.i Demo(Title.s = #Null$,Width.i = 600,Height.i = 400)
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected sync.i
  Protected clock.i
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags)
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    Repeat
      Repeat
        wnd_event = WindowEvent()
        If wnd_event = #PB_Event_CloseWindow
          wnd_exit = #True
        EndIf
      Until wnd_event = #Null
      ;-------------------------------
      clock = ElapsedMilliseconds()
      sync = WaitForVerticalBlank()
      Debug ElapsedMilliseconds() - clock
      Debug sync
      ;-------------------------------
    Until wnd_exit
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Demo("VSYNC")

End


U might want to add some timers and some sort of delay/event to release some cpu time ;)


Top
 Profile  
Reply with quote  
 Post subject: Re: Is possible wait for vertical blanking on windows?
PostPosted: Mon Mar 16, 2020 10:56 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1801
Location: Pas-de-Calais, France
Welcome ! I commit this code some years ago : viewtopic.php?f=12&t=36852


Top
 Profile  
Reply with quote  
 Post subject: Re: Is possible wait for vertical blanking on windows?
PostPosted: Tue Mar 17, 2020 12:32 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 22, 2016 5:33 pm
Posts: 139
Location: Spain
Thanks both for the code examples, I will take a look and try to insert something like that on my own code :wink:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: swan and 49 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye