jmasterx
jmasterx

Reputation: 54123

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 written 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

Upvotes: 2

Views: 3577

Answers (1)

Fred Foo
Fred Foo

Reputation: 363617

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.

Upvotes: 7

Related Questions