SFML community forums
Help => Graphics => Topic started by: Ashenwraith on April 12, 2010, 09:53:04 pm
-
Hi, here's an example of my probs, any help would be great:
sf::Color c1,c2;
c1=img.GetPixel(0,0);
if(c1!=c2) // doesn't compare colors
{
}
Nevermind, I forgot another check.
-
What do you mean? The compare method works fine.
-
What do you mean? The compare method works fine.
Yeah, I put in a simple 4 color image to check it, but I forgot to check if the color switched back on the next swap.
-
What do you mean? The compare method works fine.
hmmm... still having probs with it .
Are you sure this works for comparing the r,g,b,a value?
What are the bool operators for?
bool sf::Color::operator!= ( const Color & Other ) const
I can't get these to work either.
-
From SFML source code :
////////////////////////////////////////////////////////////
bool operator ==(const Color& left, const Color& right)
{
return (left.r == right.r) &&
(left.g == right.g) &&
(left.b == right.b) &&
(left.a == right.a);
}
////////////////////////////////////////////////////////////
bool operator !=(const Color& left, const Color& right)
{
return !(left == right);
}
It mean what is write. =p Are you sure you compare the right color, including alpha channel?
-
yeah, yeah.. I know
I don't know what's wrong with my code.
It would help if there was a way to print all these variables.
It's hard to tell if they are working.
-
yeah, yeah.. I know
I don't know what's wrong with my code.
It would help if there was a way to print all these variables.
It's hard to tell if they are working.
void PrintColor(const sf::Color &Color)
{
std::cout << Color.r << ", " << Color.g << ", " << Color.b << ", " << Color.a << std::endl;
}
-
yeah, yeah.. I know
void PrintColor(const sf::Color &Color)
{
std::cout << Color.r << ", " << Color.g << ", " << Color.b << ", " << Color.a << std::endl;
}
Thanks, I got it working.
hmmm... I tried
std::cout<<my_color.a<<'\n';
But it was only blank.
Why does your code work?
I think it might be the windows console, I get strange characters for a lot of these cout.
-
Hmm.... I think you should show some relevant code. I'm kinda lost :-D
-
Keep the \n for the printf thing, use std::endl with the std::cout instead. :p
And I agree, show some codes. It's easier to help you while seeing your code (and your mistakes) that without. :p
-
I think it might be the windows console, I get strange characters for a lot of these cout.
Or maybe you just need to write <<"\n" instead of <<'\n', or at least '\n\0'. C(++) uses null-terminated strings. ("string" means string + \0)
-
hmmm... I tried
std::cout<<my_color.a<<'\n';
But it was only blank.
The sf::Color members are of type sf::Uint8, which is a typedef for unsigned char. And the unsigned char overload of std::ostream::operator<< tries to write characters, not numbers. So, you have to cast to a type that is recognized by the streams as a number:
std::cout << static_cast<int>(my_color.a) << std::endl;
Or maybe you just need to write <<"\n" instead of <<'\n', or at least '\n\0'.
No, that's not the problem. std::cout can handle single characters. And '\n\0' is not a valid char literal, you can't store two characters in one byte.
-
hmmm... I tried
std::cout<<my_color.a<<'\n';
But it was only blank.
The sf::Color members are of type sf::Uint8, which is a typedef for unsigned char. And the unsigned char overload of std::ostream::operator<< tries to write characters, not numbers. So, you have to cast to a type that is recognized by the streams as a number:
std::cout << static_cast<int>(my_color.a) << std::endl;
Or maybe you just need to write <<"\n" instead of <<'\n', or at least '\n\0'.
No, that's not the problem. std::cout can handle single characters. And '\n\0' is not a valid char literal, you can't store two characters in one byte.
Hey thanks with the cast help. That's what I thought it was. I haven't used C++ in a while and this new syntax looks good without having to use a lib like boost. I'll have to check to see if it works with wchar_t and other stuff I'm working with.