Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consoles are not setting the background color by default. #88

Open
jpuertos opened this issue Jan 27, 2021 · 9 comments
Open

Consoles are not setting the background color by default. #88

jpuertos opened this issue Jan 27, 2021 · 9 comments
Assignees
Labels
documentation Documentation needs to be updated.

Comments

@jpuertos
Copy link

I am attempting to print colored text using 'setColorControl', the foreground is color is correctly set but not the background.

In my main loop I have:

TCODConsole::root->setDefaultBackground(TCODColor::black);
TCODConsole::root->clear();
...
TCODConsole::setColorControl(TCOD_COLCTRL_1, TCODColor::gold, TCODColor::blue);
TCODConsole::root->printf(0, 0, "%ccolored%c not colored", TCOD_COLCTRL_1, TCOD_COLCTRL_STOP);
     
TCODConsole::flush();
   

am I doing something wrong?

@jpuertos
Copy link
Author

Tried using different renderers but same issue.

@HexDecimal HexDecimal added the bug label Jan 27, 2021
@HexDecimal HexDecimal self-assigned this Jan 27, 2021
@HexDecimal
Copy link
Collaborator

I don't see anything wrong with your code example. The C++ API forwards to the C API so this issue should have been reproducible in the Python port as well, but it worked correctly when I tried it in python-tcod.

Which version of libtcod are you using? Be sure to use the latest alpha release.

Sample the background color after printing to make sure the issue is here:

TCODConsole::root->printf(0, 0, "%ccolored%c not colored", TCOD_COLCTRL_1, TCOD_COLCTRL_STOP);
TCODColor bg = TCODConsole::root->getCharBackground(0, 0);
printf("%d,%d,%d", bg.r, bg.g, bg.b);

@jpuertos
Copy link
Author

I am using libtcod/1.16.0-alpha.15@hexdecimal/stable

printf tells: 0,0,0

@jpuertos
Copy link
Author

libtcod is built locally, as it comes as a conan source package. no warnings during build

@HexDecimal
Copy link
Collaborator

Thanks for the input. I think I've successfully reproduced the error in C++ and can take it from here.

@HexDecimal
Copy link
Collaborator

The issue was that the console background flag is unset. The default value is TCOD_BKGND_NONE which leaves the background color unaffected. So you need to set this attribute before calling print:

TCODConsole::root->setBackgroundFlag(TCOD_BKGND_SET);  // Now the background colors will be set as expected.
TCODConsole::root->printf(0, 0, "%ccolored%c not colored", TCOD_COLCTRL_1, TCOD_COLCTRL_STOP);

I've forgotten this was the normal behavior of libtcod. Losing track of the 'console defaults' has been a frequent issue so I wrote python-tcod to bypass these defaults completely. That is why I couldn't reproduce the issue there.

This is the correct behavior of TCODConsole. It's unintuitive and to me it's a reminder of why I wanted to rewrite the C++ API in the first place.

@jpuertos
Copy link
Author

Thanks for your help, now it works. I think it would be a good idea to mention about it in the 'printing with color control' documentation section.

@HexDecimal
Copy link
Collaborator

The documentation still needs to be rewritten. The v1.6.4 docs are effectively read-only.

@HexDecimal HexDecimal changed the title setColorControl not setting the Backgound color in Linux Consoles are not setting the background color by default. Jan 28, 2021
@HexDecimal HexDecimal added the documentation Documentation needs to be updated. label Sep 27, 2021
@hazeled
Copy link
Contributor

hazeled commented Sep 26, 2022

Should the "Bug" label be removed from this?

@HexDecimal HexDecimal removed the bug label Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation needs to be updated.
Projects
None yet
Development

No branches or pull requests

3 participants