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

Author Topic: Vertical line artifacts in simple image  (Read 1813 times)

0 Members and 1 Guest are viewing this topic.

bclever

  • Newbie
  • *
  • Posts: 1
  • Just starting with SFML
    • View Profile
Vertical line artifacts in simple image
« on: February 10, 2018, 06:14:59 pm »
Hello all, I apologize for the noob level question... In this basic SFML code I can't figure out where the
black vertical lines are coming from. Any help would be appreciated.

(BTW using Visual Studio 2017 on Windows 10 running on a partitioned iMac.)

int main()
{
        sf::RenderWindow window(sf::VideoMode(520, 480), "Vertical lines issue??");

        while (window.isOpen())
        {
                sf::Event event;

                window.clear();
                drawBasicFlat(window);
                window.display();

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }
        }

    return 0;
}

//-------------------------------------------------------------
void drawBasicFlat(sf::RenderWindow& theWindow)
{
        unsigned max_x = theWindow.getSize().x;
        unsigned max_y = theWindow.getSize().y;

        unsigned vertexCount;

        for (unsigned x = 0; x < max_x; ++x)
        {
                sf::VertexArray line(sf::Points, max_y);

                for (unsigned y = 0; y < max_y; ++y)
                {
                        line[y].position = sf::Vector2f(x + 1, y + 1);
                        line[y].color = sf::Color(150, 100, 75);
                }

                theWindow.draw(line);
        }
}

 
« Last Edit: February 16, 2018, 11:41:16 am by eXpl0it3r »

dmitry_t

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Vertical line artifacts in simple image
« Reply #1 on: February 16, 2018, 08:13:15 am »
A screenshot, please?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Vertical line artifacts in simple image
« Reply #2 on: February 17, 2018, 03:37:47 pm »
Without seeing a screenshot, I could guess that it's because of the positioning of the points.
Points are the 'centre' of the point. The co-ordinate of (0, 0) for example) in a default view) is the very corner of the window, not the top-left pixel. To draw that pixel, you need to fill from (0, 0) to (1, 1). Drawing a point fills the entire pixel that it is in inside. If the co-ordinate is (1, 1) though, it may choose any of the four pixels that share that corner.

The solution then, when drawing points, is to add (0.5, 0.5) to each (rounded) pixel co-ordinate. This places the point in the centre of the pixel.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*