dcsimg
Results 1 to 3 of 3

Thread: How do I detect VSync with Windows API in VB6?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    965

    How do I detect VSync with Windows API in VB6?

    I want to make a video player that updates the currently displayed frame with the next frame from the video file at a rate of EXACTLY 30 frames per second. To do that, the easiest way is to detect when the end of the video card's frame drawing signal has happened (much harder is to get an accurate timer precise to exactly 33.33333 milliseconds, and not only that make sure that the timer starts at the exact start of the frame drawing), so I can immediately load the next frame into video memory via SetDIBits or SetDIBitsToDevice or BitBlt (depending on how the rest of my code is set up).

    But the problem next is HOW do I use Windows API to detect VSync? Does Windows API even have a function to detect VSync? It would be nice is there was a VSync callback that I could use, that would automatically call a userdefined function whenever the graphics card signaled VSync (a function which I would write to load the next frame).

    Something like:
    Code:
    SetVSyncCallback AddressOf Module1.VSyncCallback
    Then the VSyncCallback function in Module1 would simply contain the code to load the next frame.

    I know that DirectX has a way to poll for the next VSync signal, but that is hardly ideal. That requires the DirectX SDK for VB6, which is no longer available from Microsoft. And there is no way to directly use DX in VB6 without the DX SDK (the actual DX functions are CDECL functions, not StdCall, so VB6 can't handle that directly, instead requiring the use of LoadLibrary, GetProcAddress, and DispCallFunc, which is a lot of extra overhead to writing the program). So I'm looking to avoid DX altogether, and write my program using only VB6 code combined with a few simple Windows API functions. So does anybody here know of any Windows API functions that would let me set up a VSyncCallback function?

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,620

    Re: How do I detect VSync with Windows API in VB6?

    There is no Windows API function to catch, poll, or report VSync. DirectX or another Graphic library that has low level access to the video card would be your only choices.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    965

    Re: How do I detect VSync with Windows API in VB6?

    Quote Originally Posted by passel View Post
    There is no Windows API function to catch, poll, or report VSync. DirectX or another Graphic library that has low level access to the video card would be your only choices.
    Interesting. At some point, the API must communicate with the graphics card via the driver (even if only the default driver). You'd think that MS would have included an API function (and default driver functionality for it to work with) that would have allowed a standard program to call that function to poll the VSync state. I wonder why they didn't? And how (without this) does Windows Media Player even work? When playing video, the software must somehow sync with the monitor's VSync to keep the frames being displayed at the exact moment they should (or risk the "tearing" effect in the video playback). Is there some undocumented function to do that that Windows Media Player is using?
    Last edited by Ben321; Oct 3rd, 2018 at 03:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width