bool WaitOpenGlStatus(int goodOpenGlStatus, int waitSeonds)
{
timespec timeNow1;
clock_gettime(CLOCK_MONOTONIC, &timeNow1);
while (true)
{
if (glGetError()==goodOpenGlStatus)
return true;
sleep(1); // sleep 1 second
timespec timeNow2;
clock_gettime(CLOCK_MONOTONIC, &timeNow2);
if ((timeNow2.tv_sec- timeNow1.tv_sec)>waitSeonds)
return false;
};
}