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

Author Topic: SFML 2.5.1 - Windows 10 - Line draws with incorrect colour on top of Vertex  (Read 993 times)

0 Members and 1 Guest are viewing this topic.

NightShadeI

  • Newbie
  • *
  • Posts: 7
    • View Profile
Minimal reproducible example:

static auto WHITE_COL = sf::Color{255, 255, 255, 255};
static sf::Vertex myQuads[] = {
    sf::Vertex{sf::Vector2f{100.f, 100.f}, WHITE_COL },
    sf::Vertex{sf::Vector2f{200.f, 100.f}, WHITE_COL },
    sf::Vertex{sf::Vector2f{200.f, 200.f}, WHITE_COL },
    sf::Vertex{sf::Vector2f{100.f, 200.f}, WHITE_COL },
};
aWindow.draw(myQuads, 4, sf::Quads);

static auto BLACK_COL = sf::Color{0, 0, 0, 255};
static sf::Vertex myLines[] = {
    sf::Vertex{sf::Vector2f{110.f, 150.f}, BLACK_COL},
    sf::Vertex{sf::Vector2f{190.f, 150.f}, BLACK_COL},
};

aWindow.draw(myLines, 2, sf::Lines);

This results in a gray line with RGB (99,99,99)

Oddly, adding another line 1 pixel below will resolve the issue, and the now "thickness 2" line is now black. Further, a rectangle will also be of a black colour. I'd prefer to be using a line here though.

I also tried adding sf::BlendNone , this does not help and results in the same outcome.

What is going on here?

Thanks :)

« Last Edit: November 14, 2022, 02:42:11 pm by NightShadeI »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Your code does seem to do exactly what is expected: a black, single pixel (infinitely thin) line on a white square.
See attached image; it's your code, screen-captured and scaled up in image software to see the pixels clearly. The black line is exactly (0, 0, 0).

Is it possible you have some sort of scaling involved? If you are 'technically' drawing to fewer pixels than expected, grey could be due to the black not taking up an entire pixel.

I also wonder if anti-aliasing could do this although it shouldn't with a perfect line.

It's hard to judge without knowing your set-up and the rest of the code you use.

Try it again with the common 'trick' of putting the points of the line half a pixel down and right - add (0.5, 0.5) to each co-ordinate - to put it in the middle of those pixels and see if that displays any differently.
« Last Edit: November 14, 2022, 04:51:03 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

NightShadeI

  • Newbie
  • *
  • Posts: 7
    • View Profile
Ah yes right you were, I had antialiasing and totally forgot I had it enabled  , thanks a lot for helping me track that one down. Interesting it had an effect

 

anything