Jump to content
  • Advertisement
Sign in to follow this  
Darkbluesky

Synchronization with refresh rate (vertical sync) - Not for game

This topic is 3271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am working on a project which is not a game although it is to be used with them. My app does not use graphics, it is a form and thus I chosed C# to develop it. Summarizing, my app is an interface to an external circuit that generates a square wave (0-5v) at a given frequency and time offset. I have done the device and programmed in a way that it is able to generate a square wave on its own, and I am able to control its frequency and time offset from my application in an arbitrary way. The tricky part is that square wave drives a pair of shutter glasses which must be in sync with the refresh rate of the screen in order to see games in stereoscopy (i.e. real 3D with real depth). The problem is that I need to send from the application to the device, a sync "pulse" (not necessary a full square wave) with the frequency of the refresh rate (vertical sync). That pulse will be a simple code, which the device will identify. It doesn't matter if the pulse/code is sent in the scan line 56, 0, in the beginning of the vertical blank, or whatever, as far as the pulse/code is sent always at the same scan line (more or less...) I wanted to create a thread that would check constantly for the scanline of choice, and when it finds it, send the pulse, but I need a way to read the current scan line or beginning of blank period, etc. After looking for 2 weeks on internet, I have only found some DirectDraw function (deprecated), and examples or libraries/functions oriented to "frame display" at vertical sync only, afaik. I would need a simple function that gives me the info of the scanline or vertical blank, but without the work of initializing direct3D or directDraw. After 2 weeks of searching in internet I feel I am in a dead end. So I decided to write here. Maybe you could give an example or point me towards a solution? I am an average C++, C# programmer (hobbist) but I don't know DirectX and I would like to learn, but in the future, not now, if possible; I am afraid that it would be too late for my application if I have to start from scratch in D3D... I wonder if someone could try to help me. Thank you very much

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I would need a simple function that gives me the info of the scanline or vertical blank, but without the work of initializing direct3D or directDraw.


You can't get that information under Windows. You'd need a custom driver to emulate it or something similar. The problem with vsync is that it's a fairly dated concept as far as all those original signals go, with all the LCDs and GPUs and whatnot.

Scanlines were relevant to CRTs simply due to the way the image was generated. While the approach is still similar, it's far less important as such.

The DX doesn't offer this information either, it merely gives the option to let driver redraw when appropriate to attempt to minimize tearing.

The closest you could come to is implement a timer, that would trigger based on frequency reported by current display mode.

Share this post


Link to post
Share on other sites
Quote:
Original post by Darkbluesky
Summarizing, my app is an interface to an external circuit that generates a square wave (0-5v) at a given frequency and time offset.

I have done the device and programmed in a way that it is able to generate a square wave on its own, and I am able to control its frequency and time offset from my application in an arbitrary way.

The tricky part is that square wave drives a pair of shutter glasses which must be in sync with the refresh rate of the screen in order to see games in stereoscopy (i.e. real 3D with real depth).

That seems kind of circuitous (heh pun). Why involve the computer at all? Why not just put the circuit inline on the VGA connector, watching the vsync line?

Share this post


Link to post
Share on other sites
Your computer's VGA port is currently generating that sync pulse for you - pin 14, VSYNC. I recently experimented with 3D shutter glasses on my PC, and found a robust solution in interlaced video modes and a a fiver's worth of electronics - there's more info on my website (reverse date order) if it would be of use!

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
That seems kind of circuitous (heh pun). Why involve the computer at all? Why not just put the circuit inline on the VGA connector, watching the vsync line?


Quote:
Original post by benryves
Your computer's VGA port is currently generating that sync pulse for you - pin 14, VSYNC. I recently experimented with 3D shutter glasses on my PC, and found a robust solution in interlaced video modes and a a fiver's worth of electronics - there's more info on my website (reverse date order) if it would be of use!


Thank you for your suggestions!
Nevertheless that is the first circuit I did, plugged in the VGA connector, it takes that signal and delay it with two NE555 timer chips.

That worked but it is a bit tricky to do for other people with no electronic/soldering skills, and moreover, doing it from the computer will allow to save/load profiles for different pairs of frequencies and screens/projector (note that each screen/projector has its own internal delay processing the video signal, and thus a different delay (time offset) for the glasses is needed).

You can also control it by hotkeys keeping the eyes on the screen and without need to reach the device (specially useful if you are far from the pc as when using a beamer).

But now currently, with DVI connectors there is no more a square signal in any pin, except if you connect an analog monitor, but that is a particular case...

When I planned this device I thought about taking the signal from the DVI, my surprise was when it was not there with digital monitor/projectors...

[Edited by - Darkbluesky on November 3, 2009 12:00:27 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
The closest you could come to is implement a timer, that would trigger based on frequency reported by current display mode.


Quote:
Original post by Erik Rufelt
If you just want the refresh rate, you can try EnumDisplaySettings. Not sure how to call it from C#, but the documentation says it's in User32.dll.


Thanks for your answers.

I am afraid though, that the reported display freq, will give my a "nominal" freq, but not the real one; the one sent by the gpu. I mean, that in order to avoid de-synchronization during the time, I need precision of 0.01-0.02 Hz. Summarizing I am afraid that the reported freq will be 120 Hz, but the real one is maybe 119.997 Hz. This difference could make slip the synchronization.

I'll try EnumDisplaySettings though.

On the other hand, I am thinking if maybe I should use DirectDraw after all, although it is deprecated...But how can I do a simple function/library that allows to use GetScanLine? Does it exists something already done...?

[Edited by - Darkbluesky on November 3, 2009 12:20:15 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!