color problems with text

This is a discussion on color problems with text within the Game Programming forums, part of the General Programming Boards category; I know this is a FAQ, but none of the other posts have the answer im looking for. I was ...

  1. #1
    Unregistered
    Guest

    color problems with text

    I know this is a FAQ, but none of the other posts have the answer im looking for. I was wondering how to change the color of the text as follows:

    lets say that this is what the program displayed:

    this is blue //in a blue color
    this is darker blue //guess what? a darker blue color
    this is red //i think you can figure this out by yourself...
    this is darker red
    this is standard white
    this is green
    this is darker green

    I have read the other posts on this and they all suggest an alternative approach that i found to be very un-reliable (as in the colors would change without me telling the to) and you couldnt switch the color back to white... Is this possible and how can i do it?

  2. #2
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,420
    what api?

  3. #3
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    Posts
    140
    if you're using the windows dos-console then
    red baron's game "dungeon of moria" will
    be a very good example for colored text mode...

    i don't have a link by the hand, but i am sure you can
    find a post of red baron with the link in the signature

  4. #4
    Unregistered
    Guest
    um... ok... i am using microsoft C++ (on a pc...) if anyone is wondering.

    P.S. that whole red barron thing isnt very helpful without a link...

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Code:
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    and i'm pretty sure you have to #include <conio.h>

    the number 8 is what you'll change to get a different color. 0 is black and so forth. take out | FOREGROUND_INTENSITY if you don't want the colors to be bright.

    btw, there are tons of posts about this here.

  6. #6
    Unregistered
    Guest
    i have heard of that b4, and actually saw it in a thread, but i didnt know you could use numbers! Thanx a lot, ill try it

  7. #7
    Unregistered
    Guest
    um... ya... error heaven. Here is what my compiler thinks of this


    : error C2065: 'SetConsoleTextAttribute' : undeclared identifier
    : error C2065: 'GetStdHandle' : undeclared identifier
    : error C2065: 'STD_OUTPUT_HANDLE' : undeclared identifier
    : error C2065: 'FOREGROUND_INTENSITY' : undeclared identifier


    what the HECK is wrong here?

  8. #8
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    did you #include <conio.h>?

    and by the way here is a site that lists all of the ascii code descriptions.

  9. #9
    Unregistered
    Guest
    ok i figured it out, its #include <windows.h>, but thats not the problem. The problem is that after a while of changing color, the color goes wako and reverts to the origianl grey-ish annoying thing. What did i do wrong? Another thing thats wierd is that only PARTS of the text changes color for instance:

    Title <--supposed to be blue, but is normal grey
    wannanno! whoop whoop wh/*it turns completly white here*/oop whoop! wa/*it turns back to normal grey here*/nnanno!
    you can go left <---- supposed to be blue, but in normal grey


    It works for a bit then does this

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    Try including <stdio.h>, and make sure to code in the following (above where you start changing colors)
    Code:
    HANDLE hStdout;
    That normally works for me. And I think you have to use printf instead of cout, or something bad happens (don't remember what).
    "Um...well..."
    -Kyoto Oshiro

  11. #11
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    i advise that if you use \n its not a good idea cause it colours the whole line that colour and make sure you put the set colour command before typing in a line for all lines. and just for the hell of it check out the attachment and if you have time my game good luck

    ps if it still does not work post a bit of your code instead of only the output
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  12. #12
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    dang it forgot to attach
    Attached Files Attached Files
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  13. #13
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    Posts
    140
    red baron's code snippet works very well !

  14. #14
    Unregistered
    Guest
    hm..... this is getting bad because it is still not working... Here is my code (yes i know, it is very confusing, but maybe somebody a little bit brighter than me can see the problem)
    One more thing b4 i show the code... how do i put it in that nice little thig that say "code:" becuase what i will post is about 100 lines...

  15. #15
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,420
    ["code"]

    code goes here

    ["/code"]

    you have to remove the quotation marks.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 10:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21