Kairichan
12-21-2009, 05:45 AM
Hi,
I an relatively new to C++ and OpenGL.
I am trying to create a rhythm game which allows players to tap on certain keys to the beat timing. I am using fMod for the sound and OpenGL for the graphics. I am using glutTimerFunc to play the "ticks" for each beat and for a quad to display a different colour.
The problem I am facing is that glutTimerFunc only takes in milliseconds. If a song has a bpm (beats per minute) of 166, a simple calculation 60000/166 will give us the milliseconds between each beats and in this case is 361.44. This means the timer must fire again at exactly 361.44 milliseconds in order for the ticks and colour change to be in sync with the song.
Since glutTimerFunc can only take milliseconds as integers, I cannot pass 361.44 into it and rounding to 361 or 362 makes everything off-sync towards the end of the song. Furthermore, the timer does not always fire at exactly the millisecond you tell it to. A simple timeGetTime() calculation informed me that glutTimerFunc fired at anything between 358 - 363 millisecond when I have given it 361. Such inconsistancies have a huge impact to my timing-critical game.
Is there any ways at all to get glutTimerFunc to fire at half milliseconds for example and each time it fires, it does it at the very precise time. If not, what other strategies can I adopt?
Thanks
I an relatively new to C++ and OpenGL.
I am trying to create a rhythm game which allows players to tap on certain keys to the beat timing. I am using fMod for the sound and OpenGL for the graphics. I am using glutTimerFunc to play the "ticks" for each beat and for a quad to display a different colour.
The problem I am facing is that glutTimerFunc only takes in milliseconds. If a song has a bpm (beats per minute) of 166, a simple calculation 60000/166 will give us the milliseconds between each beats and in this case is 361.44. This means the timer must fire again at exactly 361.44 milliseconds in order for the ticks and colour change to be in sync with the song.
Since glutTimerFunc can only take milliseconds as integers, I cannot pass 361.44 into it and rounding to 361 or 362 makes everything off-sync towards the end of the song. Furthermore, the timer does not always fire at exactly the millisecond you tell it to. A simple timeGetTime() calculation informed me that glutTimerFunc fired at anything between 358 - 363 millisecond when I have given it 361. Such inconsistancies have a huge impact to my timing-critical game.
Is there any ways at all to get glutTimerFunc to fire at half milliseconds for example and each time it fires, it does it at the very precise time. If not, what other strategies can I adopt?
Thanks