Console output, with COLOR? and fast

Started by
14 comments, last by n0ob 19 years, 6 months ago
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!
Advertisement
Been a while but do a search for:

SetConsoleTextAttribute()

That is what I used but don't remember the exact details.
Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
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");}

Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
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!
Quote:Original post by n0ob
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!


You can re-call SetConsoleTextAttribute. What are you doing that you need it faster? It should be very fast on that level.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Write to 0xB8000 newb
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.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Quote:Original post by Anonymous Poster
Write 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 ^_^
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.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Quote:Original post by Anonymous Poster
Write 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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement