PDA

View Full Version : frame synch



geohoffman49431
06-16-2004, 11:05 AM
What is the best way to synchronize my display? For now I am only using windows for learning so I don't mind using windows specific code for now. This is what I though would work:


DWORD time;

public void display()
{
//renderscene
while (GetTickCount() - time < 20) ; //time is initialized in my setup function so it will work the first time
time = GetTickCount();
}I did not want to use something like Sleep(30);. I think that would mean the time between each frame would be equal to (the time it takes to render the scene) + 30 miliseconds. This would mean a variable rate depending on how long it takes to render the scene. The above method makes sure that every 20 miliseconds we display one frame of animation (unless it takes longer than 20 miliseconds to render the scene). But I notice that the function call GetTickCount is really slowing my program down. If I change it to:


DWORD time;

public void display()
{
//renderscene
while (GetTickCount() - time < 0) ;
time = GetTickCount();
}it is a lot slower than if I just comment out the whole thing.

I would also like to be able to do AI/collision detection/etc while the frames are synching. Any suggestions?

ZbuffeR
06-16-2004, 12:39 PM
wglSwapInterval(1) ?

geohoffman49431
06-16-2004, 03:57 PM
what exactly do you mean? I looked on google and found only 2 hits for wglSwapInterval. What does it do?

CrazyButcher
06-16-2004, 11:01 PM
http://oss.sgi.com/projects/ogl-sample/registry/EXT/wgl_swap_control.txt

yooyo
06-17-2004, 03:13 PM
Depending on sync you need you have 2 solution:
1. Sync to monitor refresh... use wglSwapInterval(1) before render loop.
2. If you want your own fixed framerate you have to use Windows Multimedia timers. Search MSDN for
timeGetDevCaps,
timeBeginPeriod,
timeSetEvent

Win MM timer are very accurate. If you use SetTimes & KillTImer call your app will not run well.

yooyo