Dark Bit Factory & Gravity

GENERAL => General chat => Topic started by: vtlmks on June 18, 2017

Title: Remake; vsync & timing
Post by: vtlmks on June 18, 2017
So, I'm doing a few Amiga remakes. But I haven't come up with a good way to solve the timing.

There are a lot of refresh rates out there, even if we only take into account the LCD ones. 60Hz, 100Hz, 120Hz, 132Hz, 144Hz; only one divisible with 50Hz (Amiga Pal).

What I could do is let 60Hz run at 60Hz; 100Hz, 120Hz, 132Hz I divide by two, which would suck for 132Hz - 66hz refresh rate, and divide 144Hz by three, making the remake run a tad bit slow. And any refresh rates I don't know of, or can't query from windows with GetDeviceCaps(... VREFRESH) I'd just have to run at full speed I guess.

Or I could make sure to update a frame in 20ms (50Hz) and do a SwapBuffers(..) then and have it tear and look very non-smooth. What would be the preferred way?

Some background; I'm doing the rendering to a 352x272 pixel buffer, and I rather want to not use sub-pixel scrolling with openGL, else it would be a lot simpler. However, if that is the only way to solve it I might think it over again, but I rather hope not, would be very nice with integer pixel positions.

Well, Thanks for your time, and I hope to get some fun ideas to explore :) Cheers!
Title: Re: Remake; vsync & timing
Post by: Rbz on June 18, 2017
Hi vtlmks,

It's really a hard problem, I've read/watched a lot on this topic and I'm still not sure the correct way to solve it either.

For my little intros, I'm still using something like this:
Code: [Select]
FrameRate = (double)(((double)HTimerVal.QuadPart - LastTickCount)/HTimerFreq);
LastTickCount = (double)HTimerVal.QuadPart;

I've watched some videos by Casey Muratori about this topic, check out it here (https://hero.handmade.network/episode/code/day018), it's a great explanation about variable framerate monitors, and will try it someday, might be useful for you too.
Title: Re: Remake; vsync & timing
Post by: vtlmks on June 18, 2017
Hi rbz,

Thanks for the link, I'll check it out right away. I did more or less exactly what you do when I just used GDI to display my software rendered frame, but now that I changed to display the frame with openGL the problem got a bit worse as many people either force, or disable, vsync completely.

Thanks again!
Title: Re: Remake; vsync & timing
Post by: Rbz on July 02, 2017
I found some people talking about directdraw "WaitForVerticalBlank" function, so I've made a test and it seems to work.

I've a laptop that runs opengl programs at 120+ fps and after applying WaitForVerticalBlank it get synchronized with monitor refresh rate which was 60hz.

Check it out to see if this have any use for you.

Attached an example here for you to test, press "Enter" to switch on/off WaitForVerticalBlank, ESC to exit.
Title: Re: Remake; vsync & timing
Post by: vtlmks on July 05, 2017
Thanks, I checked it out, seem to work great, easy solution. :)

I also watched the episode with Casey Moratori that you linked to, and made a similar delay as he did to sync to an arbitrary frame rate (50Hz in my case), I was thinking that I will have a switch to select between that and 60Hz.

Title: Re: Remake; vsync & timing
Post by: Rbz on July 05, 2017
Looking forward to see those remakes  :D
Title: Re: Remake; vsync & timing
Post by: vtlmks on July 06, 2017
One of them is almost ready for release, I went on a sidetrack by starting to write a debugsystem/profiler, but I'll try to finish it up soon, one of the remakes I'm doing is 'Fashion - Fashinating' megademo (4 parts) Always liked that one, the other one I've started on is the 'Spreadpoint - Woooow' demo.

I wont set a date as I'm also in the midst of moving houses so could take a few weeks, but should be sooner.