Double buffering in the console (display)?
I'm trying to create a console pong game but have run into the following issue. I have the following:
int main()
{
while(1)
{
clearScreen();
std::stringstream sstr;
for(int i = 0; i < 20; ++i)
{
sstr << "Mooooooo \n";
}
printf(sstr.str().c_str());
restThread(50);
}
return 0;
}
The output I would expect is for Moo to be w开发者_JAVA百科ritten 20 times and for the contents of the screen to never actually change. However it flickers from time to time. I suspect this is because the output is shown to the screen before it is fully drawn. Is there a way around this? eg, not showing the user anything until all the characters have been drawn to the screen?
Thanks
There's the curses/ncurses library, which requires you to refresh the screen before anything is displayed. It's pretty ubiquitous in terms of platform support.
精彩评论