I'm currently using TinyPTC in GDI mode (yeah I know, outdated and stuff) to be able to use a backbuffer and flip it to the GDI surface, it's pretty neat for doing simple 2D rendering the old pixel-fashioned way.
I want to flip the buffer every frame, being 60Hz, how can I do this in a very timing-precise way?
Currently I use a very slow and unaccurate jittering way like this:
unsigned int buffer[WIDTH * HEIGHT];
static int next_tick = 0;
static int tick_interval = (int)(1.0f * 1000.0f / 60.0f);
void syncframe(void)
{
if (next_tick >= timeGetTime())
{
Sleep(next_tick - timeGetTime());
}
next_tick = timeGetTime() + tick_interval;
}
int main()
{
while (running)
{
/* clear buffer */
/* run functions that plot pixels to buffer */
/* flip buffer and sync frame */
ptc_update(buffer);
syncframe();
}
}
It sure does work, but it lags rhythmically. I know there's no way to get 100% fullspeed on a multitask system, because there are several low-level threads in use by the OS....
But there should at least be a way to get 60Hz smooth, 60Hz is not extremely fast - would triple buffering help? Any known tricks and tips to get this working in a simple way? As said, this is simple software 2D stuff.
Any help appreciated!