Thread: 256 colors possible?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    42

    256 colors possible?

    Currently, I'm programming in C and making a console program and could only use the 15 colors. Is there a way to continue making a console program that will use 256 colors? This is all in Windows. I'm using Visual Studio 2019.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    The console was finally updated in Windows 10, to support 8-bit and 24-bit color.

    Oh, about your question, I think that Windows 10 console accepts ANSI escape codes.
    Last edited by GReaper; 08-01-2019 at 08:57 AM.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    I have two different programs I've made. I created a function that changes the textcolor for both foreground and background, but it only does 15 colors. In one of those programs, I use the escape sequences to change the colors as well within the printf statement. But for some reason, my second program doesn't accept them. I get a question mark character where the \033 is. I'm using the same headers in both programs. Not sure why that's happening.

    People also talk about using ncurses. But I could not get it to work at all with my programs. I'm well versed in the programming stuff, but when it comes to configuring the compiler, I don't have a clue on that.

    I'll have to try that 8 bit section to see if I can get those other colors to work. If anyone has any code that can demonstrate more than the 15 colors, that would be great to see.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by edomingox View Post
    But for some reason, my second program doesn't accept them. I get a question mark character where the \033 is. I'm using the same headers in both programs. Not sure why that's happening.
    Maybe your second program doesn't generate those escape codes correctly?
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    I double checked the program. I may be wrong. I have the #defines to use them in printf statements but I'm not actually using them. I'm using the textcolor(int); function that you see everywhere. I know it used to work before. maybe that was when my laptop was running windows 7. but that was a long time ago. I can try to see if the program works, but I'm guessing it's going to fail as well.

    I tried doing different things with the escape codes. No escape code works at all in my programs. For instance, this:
    Code:
    printf(“\033[0;31m”);
    produces a weird character for \033, followed by the rest of the characters.

    I liked it back in the day when the ascii codes generated the happy face, all the suits for cards, arrows. But now, those codes don't work and I can't get unicode to work at all. I don't know what I'm doing wrong. Maybe missing a certain header? Created the project in the wrong format? Need certain libraries? Bad operating system?
    Last edited by edomingox; 08-02-2019 at 05:16 AM.

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    I'll try this to fix my unicode issue. YouTube

    Would this work?
    Code:
    set_mode(VGA_256_COLOR_MODE);
    I found it here: 256-Color VGA Programming in C - bitmap.c

    I'll have to explore this route when I get home from work.
    Last edited by edomingox; 08-02-2019 at 06:34 AM.

  7. #7
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by edomingox View Post
    I tried doing different things with the escape codes. No escape code works at all in my programs. For instance, this:
    Code:
    printf(“\033[0;31m”);
    As far as I know, Windows does not support ANSI escape codes in its terminal. In the days of the good and old MS-DOS, you could add the ANSI.SYS device driver to CONFIG.SYS, now, I don't know if this is possible or if Microsoft still provides the device driver.

    Anyway... there are other schemes to use 256 or even 24 bits colors using ANSI escape codes (256 schemes work on X11 terminals, 24 bits, I never tested): See here.

    For X11 there are a big list of ANSI sequences (here) you can use, more than ECMA-48 defines.
    Last edited by flp1969; 08-02-2019 at 06:42 AM.

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    I guess since I'm programming on a Windows 10 using Visual Studio 2019, I'm pretty much out of luck trying to use more than the 15 colors. I'm not good at programming graphics but I guess I can try to learn along those lines.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to increase Colors(More Colors)?
    By shansajid in forum C Programming
    Replies: 5
    Last Post: 01-07-2013, 09:50 AM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. Colors in C?
    By jonnyfb in forum C Programming
    Replies: 15
    Last Post: 03-21-2006, 10:38 PM
  5. Using colors
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 03-08-2002, 10:13 PM

Tags for this Thread