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

Colors #6

Closed
Ilohama opened this issue Dec 18, 2016 · 8 comments
Closed

Colors #6

Ilohama opened this issue Dec 18, 2016 · 8 comments
Labels

Comments

@Ilohama
Copy link
Contributor

Ilohama commented Dec 18, 2016

Trying to assign a grey color to a font seems not workinig.
I only have a white or a black color result.

@jube jube added the bug label Dec 18, 2016
@jube
Copy link
Member

jube commented Dec 18, 2016

Investigating this weird bug...

@jube
Copy link
Member

jube commented Dec 18, 2016

I cannot reproduce your bug. I created a test case in tests/bugs/bug6.cc (in the develop branch) and it displays a gray text as expected. Could you give me a piece of code that does not work?

@Ilohama
Copy link
Contributor Author

Ilohama commented Dec 18, 2016

This is my function to store a Color in a gf::Color4u :
m_mainMenuLabel.setColor(gf::Color::Grey(0.5f));

and this is my function to render the final text on screen :

void Label::render(gf::RenderTarget &target) {
    gf::Text text(m_text, m_font, m_characterSize);
    text.setPosition(m_position);
    text.setColor(m_color);
    target.draw(text);
}

@Ilohama
Copy link
Contributor Author

Ilohama commented Dec 18, 2016

I found that using gf::Color::Grey() with a gf::Color4u isn't working.

@jube
Copy link
Member

jube commented Dec 18, 2016

Your bug is here. You should use gf::Color4f and not gf::Color4u. When you assign a gray color to a gf::Color4u, there is an implicit conversion from float to uint8_t which results in 0.5f being 1 (or 0). And then, when you use it in setColor, there is another conversion from uint8_t to float so 1.0f (or 0.0f) which results in white or black.

@Ilohama
Copy link
Contributor Author

Ilohama commented Dec 18, 2016

So to store a Grey value in a gf::Color4u, values should looks like { 150, 150, 150, 255} ?

@jube
Copy link
Member

jube commented Dec 18, 2016

Use a gf::Color4f, that's the simplest way to do. Otherwise, you can use gf::Color::rgba() and gf::Color::convert() (in the develop branch, the names are ugly and may change in the future) to convert from one format to another.

@Ilohama
Copy link
Contributor Author

Ilohama commented Dec 18, 2016

Okay okay, anyway, i wanted to switch to gf::Color4f, looks like a way more simplier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants