how to vsync winapi drawings

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to vsync winapi drawings



I want to draw a frame number on my monitor screen sequentially



0 1 2 3 4 5 6 7 ...



One number per one physical frame (100 times per second
on 100 Hz refresh rate monitor) Is it possible under
winapi/gdi? How to do it?





100 times per second - this will be impossible to see. Anyway, vsync solution exists only in DirectX and OpenGL. Maybe also in Direct2D - I am not sure.
– Alex F
Sep 13 '12 at 16:20




2 Answers
2



Neither GDI nor GDI+ give you access to the vsync signal.



The deprecated DirectDraw APIs had a way to wait for the vsync. Newer DirectX APIs basically do it for you when you call the appropriate Present method (though I believe there are options to not wait for the vsync).





Could you explain "the appriopriate Present method" - I do not understand it. How to do a thing, I asked for: "1" on first monitor frame "2" on the secont and so on...? Under GDI I use blitting call but my prog generates 1000 fps sometimes and 900 of it are wasted :/
– grunge fightr
Sep 13 '12 at 19:00






Anything more than ~50fps is wasted anyway as Humans can't see it.
– Deanna
Sep 14 '12 at 12:38





@Deanna: It's not that clear cut. See 100fps.com/how_many_frames_can_humans_see.htm . And they point may not be for human consumption. Perhaps it's for making some timing display that will be captured by a high-speed camera.
– Adrian McCarthy
Sep 14 '12 at 19:37



Modern versions of have the Desktop Window Manager (a compositor. See https://en.wikipedia.org/wiki/Desktop_Window_Manager). You can ask it to block until "some event" occurs that is sync'd to the video frame rate. Just call DwmFlush(). I won't link to the docs because the link will go stale.



On my machine, my app is descheduled while waiting for DwmFlush(). In other words it doesn't waste CPU cycles busy-waiting, which is nice.



I believe Windows Vista and 7 had the DWM, but it could be disabled. On Windows 8 and above it is always present.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard