Hi,
I’m new to OpenGL and I’m trying to build a simple rendering engine on Linux(Ubuntu) in C/C++.
When running however, I experience jittering/flickering. Every half a second the image is not vertically aligned any more. I first thought this is because of the lack of vertical synchronization, so I implemented a simple frame limiter:
while (!m_doExit) {
m_oldTime = m_currTime;
render();
// frame limiter
m_currTime = getTimeOfDayInMillisecs();
while (m_currTime - m_oldTime < 1000/DEFAULT_MAX_FPS) {
usleep((m_currTime - m_oldTime)*1000/DEFAULT_MAX_FPS);
m_currTime = getTimeOfDayInMillisecs();
}
}
Where DEFAULT_MAX_FPS is set to 60 per default. With this code I get like 61 to 62 fps.
However it seems that OpenGL doesn’t like the sleeping in the code, when I’m removing the frame limiter everything works fine (though I get senselessly 1200 FPS).
Is there any better method in reducing cpu load without getting the jitter effect?
I’m not a big fan of the ‘sleeping’ method either, as the system can’t catch mouse/keyboard events in that time anyway…