Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Raizor on April 26, 2012
-
All my OpenGL stuff so far that has included a scroller has suffered from a degree of jerkiness and I'd like to get my head around the problem if possible. I'm probably doing something wrong with my timing, so if anyone has any suggestions, I'd appreciate it.
As you're probably aware, I use IQ's 64k OpenGL framework as a base for most of my stuff. This uses timeGetTime() for timing. As suggested in various places (including here), I call timeBeginPeriod(1) at startup and timeEndPeriod(1) when my intro finishes. I understand that timeGetTime() works in milliseconds, so I wonder if the issue is related to the value not being granular enough.
My timer code looks something like this:
static long startTime = 0;
if( !startTime )
{
// set start time
startTime =timeGetTime();
}
float timeElapsed = 0.001f * (float)(timeGetTime() - startTime);
Using this for animating objects and the like works nicely and things appear smooth. However, when I use the timeElapsed to calculate an offscreen for scrolling a scroller it seems to jump about and looks quite jerky at times. I do something along the lines of:
scrollOffset = -timeElapsed*FloatValToControlScrollSpeed
The scroller is sometimes smooth, but goes through periods of jerkiness. I'd like to avoid using the swap interval GL extension if possible to ensure it runs nicely on machines where VSync is forced off in the gfx driver settings.
I should also point out that the framerate never drops below about 200 fps.
If anyone can see something I'm doing wrong or has a solution, please let me know.
Thanks,
Raizor
-
timeGetTime and getTickCount have a resolution of about 16ms which is not precise enough to do proper timing at >=60hz.
Use QueryPerformanceCounter (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904%28v=vs.85%29.aspx) and QueryPerformanceFrequency (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644905%28v=vs.85%29.aspx) instead.
Or get the timer from your music player (which usually runs at 44100 hz).
-
Thanks Hellfire, I'll give that a go. Many thanks :)
-
I'm using GetSystemTimeAsFileTime.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724397(v=vs.85).aspx
ULARGE_INTEGER liconvert;
GetSystemTimeAsFileTime (&ftCurrent);
liconvert.LowPart = ftCurrent.dwLowDateTime;
liconvert.HighPart = ftCurrent.dwHighDateTime;
liCurrent = (double)liconvert.QuadPart/10000;
if (liCurrent - li_oldTime > 16) {
...
sleep (1);
}
-
Thanks Knurz.
I found this (http://www.geisswerks.com/ryan/FAQS/timing.html) also. Looks interesting.
-
Thanks Knurz.
I found this (http://www.geisswerks.com/ryan/FAQS/timing.html) also. Looks interesting.
Bookmarked ;D