# Console output, with COLOR? and fast

This topic is 5390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there, I was just wondering what the fastest way to write a buffer of colored text to a console window is. But, not WriteConsoleOutput... I want lowww level, no win32 crud.. I heard a rumor you could do color in cout.. but I think the person was thinking of conio.h, which I don't really want to use either. Anyway, any function names? Assembly links? Where do I start looking if no one knows? Thanks for any help!

##### Share on other sites
Been a while but do a search for:

SetConsoleTextAttribute()

That is what I used but don't remember the exact details.

##### Share on other sites
Ok I lied, I found the old code I used. Not pretty but you should be able to figure it out.

void TitleScreen(){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED| FOREGROUND_GREEN | FOREGROUND_INTENSITY );int i[12] = {185, 186, 187, 188, 200, 201, 202, 203, 204, 205, 206 };cout << "\n\n\n";cout << "\t\t     " << (char)i[5] << (char)i[9] << (char)i[9]<<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9] << (char)i[2] << endl;cout << "\t\t     " <<(char)i[1] << "                                   " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "          CGP    PRESENTS          " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "                                   " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "        MEDIEVAL KNIGHTS V1.0      " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "                                   " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "           (C) CGP 2001            " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "                                   " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[8] << (char)i[9] << (char)i[9]<<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<< (char)i[7]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9] << (char)i[0] << endl;cout << "\t\t     " <<(char)i[1] << "                 " << (char)i[1] << "                 " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "   Programmers   " << (char)i[1] << " Special  Thanks " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "                 " << (char)i[1] << "                 " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << " Steven Bradley  " << (char)i[1] << "     Taybrin     " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << " Frank  Verduin  " << (char)i[1] << "    Pendragon    " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[1] << "                 " << (char)i[1] << "                 " << (char)i[1] << endl;cout << "\t\t     " <<(char)i[4] << (char)i[9] << (char)i[9]<<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9] <<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<< (char)i[6]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<< (char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9]<<(char)i[9] << (char)i[3] << endl;cout << endl << endl << endl;system("PAUSE");cout << endl;system("CLS");}

##### Share on other sites
Thanks, but I want to be able to have multiple colors on the screen at the same time.. And anyway, SetConsoleTextAttribute is on the same level as WriteConsoleOutput. Thanks very much for your effort though!

##### Share on other sites
Quote:
 Original post by n0obThanks, but I want to be able to have multiple colors on the screen at the same time.. And anyway, SetConsoleTextAttribute is on the same level as WriteConsoleOutput. Thanks very much for your effort though!

You can re-call SetConsoleTextAttribute. What are you doing that you need it faster? It should be very fast on that level.

##### Share on other sites
Write to 0xB8000 newb

##### Share on other sites
i would think that the "win32 crud" would be the fastest way to do it, because even if you did find a c/c++ "standard" way of doing it (which i don't think exists), those functions would have to call the operating system functions anyway.

##### Share on other sites
Quote:
 Original post by Anonymous PosterWrite to 0xB8000 newb

Well, I was looking for something like that.. Is there a way to get that to work with VC++6.0? And if those functions did end up calling OS functions, I'd still kinda like to know any :P Thanks all though ^_^

##### Share on other sites
That just writes characters into the screen buffer. Set a pointer to 0xB8000, and then start writing characters, and decrement and increment the pointer as neccesary. Honestly though, that probably isn't the safest thing to do, and may not even work all that well. It's a holdover from the dos days AFAIK. Honestly, I would just use the win32 functions, They aim to be more effective and of course, much safer. Really, they're not going to have a huge performance impact.

##### Share on other sites
Quote:
 Original post by Anonymous PosterWrite to 0xB8000 newb

This only applies to DOS applications. Win32 console applications cannot use this method, newb.

Use the Win32 Console functions. It's not hard to wrap them up into a streambuf derived class, thus exposing the functionality via C++ streams.

• 21
• 15
• 9
• 17
• 13