PDA

View Full Version : Incorrect timing



dew
05-10-2001, 12:34 PM
I have tried to use timers to sync my OpenGL scenarios. But when I move the program I have build between different platforms I donít get the result I wanted with aspect to frame contra time. Why isnít the timer the same at different platforms?
How should I do my solution?
Do I have to have the timers separate in a thread?

My code looks like this:

timerindex=SetTimer(sc->hWnd,1, 10,NULL);
.
.
.
.
case WM_TIMER:
{
if(wParam==timerindex)
{
sc-wld.systemtime+=0.01;
}
return 0;
}

Can anyone help me?
How do I sync my frames to time?
//Dew

05-11-2001, 12:42 AM
Normally the Window's timers aren't that accurate, which is why you are having problems. What you is better is to use a high resolution timer to check wheather it is the correct time to do another frame. Try looking at MSDN for:
QueryPerformanceCounter
QueryPerformacneFrequency
- Which are the prefered functions for timing but it isn't always avalible
timeGetTime() - which gives time in milliseconds but it is always avalible

You'd then have a window loop something like:

DWORD dwNextFrameTime=0;

while(1) {
while(PeekMessage(NULL,&msg,0,0,PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if( timeGetTime() > dwNextFrameTime ) {
dwNextFrameTime = timeGetTime() + 30; // which would give ~30fps
// rest of game loop processed here
}
}

dew
05-13-2001, 10:58 AM
Thanx, now it works!