Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [solved]SFML Color probs  (Read 5737 times)

0 Members and 1 Guest are viewing this topic.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]SFML Color probs
« on: April 12, 2010, 09:53:04 pm »
Quote from: "Ashenwraith"
Hi, here's an example of my probs, any help would be great:

Code: [Select]
sf::Color c1,c2;

c1=img.GetPixel(0,0);

if(c1!=c2) // doesn't compare colors
{

}


Nevermind, I forgot another check.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
[solved]SFML Color probs
« Reply #1 on: April 12, 2010, 10:04:31 pm »
What do you mean? The compare method works fine.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]SFML Color probs
« Reply #2 on: April 12, 2010, 10:11:05 pm »
Quote from: "panithadrum"
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.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]SFML Color probs
« Reply #3 on: April 12, 2010, 11:35:28 pm »
Quote from: "panithadrum"
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.

Spidyy

  • Sr. Member
  • ****
  • Posts: 493
    • View Profile
[solved]SFML Color probs
« Reply #4 on: April 12, 2010, 11:42:32 pm »
From SFML source code :
Code: [Select]
////////////////////////////////////////////////////////////
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?

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]SFML Color probs
« Reply #5 on: April 12, 2010, 11:55:14 pm »
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.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
[solved]SFML Color probs
« Reply #6 on: April 12, 2010, 11:57:57 pm »
Quote from: "Ashenwraith"
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.


Code: [Select]

void PrintColor(const sf::Color &Color)
{
    std::cout << Color.r << ", " << Color.g << ", " << Color.b << ", " << Color.a << std::endl;
}

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]SFML Color probs
« Reply #7 on: April 13, 2010, 12:11:27 am »
Quote from: panithadrum
Quote from: "Ashenwraith"
yeah, yeah.. I know



Code: [Select]

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
Code: [Select]

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.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
[solved]SFML Color probs
« Reply #8 on: April 13, 2010, 12:30:53 am »
Hmm.... I think you should show some relevant code. I'm kinda lost :-D

Spidyy

  • Sr. Member
  • ****
  • Posts: 493
    • View Profile
[solved]SFML Color probs
« Reply #9 on: April 13, 2010, 12:35:05 am »
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

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
[solved]SFML Color probs
« Reply #10 on: April 13, 2010, 12:56:17 am »
Quote from: "Ashenwraith"

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)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
[solved]SFML Color probs
« Reply #11 on: April 13, 2010, 01:17:54 am »
Quote from: "Ashenwraith"
hmmm... I tried
Code: [Select]
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:
Code: [Select]
std::cout << static_cast<int>(my_color.a) << std::endl;

Quote from: "nulloid"
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]SFML Color probs
« Reply #12 on: April 13, 2010, 09:13:02 am »
Quote from: "Nexus"
Quote from: "Ashenwraith"
hmmm... I tried
Code: [Select]
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:
Code: [Select]
std::cout << static_cast<int>(my_color.a) << std::endl;

Quote from: "nulloid"
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.