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

Author Topic: [Solved]Line issue  (Read 1590 times)

0 Members and 1 Guest are viewing this topic.

canlot

  • Newbie
  • *
  • Posts: 15
    • View Profile
[Solved]Line issue
« on: March 21, 2014, 10:21:32 pm »
I try myself on Vertexes.
I have wrote a class which have a rectangle inside and a border around.
The main porpose of the border to be kind of shadow around the box but that is not the problem.
When i display the border it have black lines like some lines is missing, and i make the border of lines(http://www.sfml-dev.org/documentation/2.1/classsf_1_1VertexArray.php)

In the first screenshot i have normal size window and there not so many black lines but in the second one maximized the window i got more of them.

code where i create the lines:

void Flat_Entity::create_border() //m_ is for member
{
            int points_count = m_border_thick*5;


            m_border.setPrimitiveType(sf::LinesStrip);
            m_border.resize(points_count);
            int increment_adress = 0; //increment for vector

            int x_near = m_x + m_border_thick;
            int y_near = m_y + m_border_thick;
            int x_far = m_x + m_width - m_border_thick;
            int y_far = m_y + m_height - m_border_thick;


            for(int size_thick = 0; size_thick < m_border_thick; ++size_thick) //size_thick represents px
            {
                    m_border[increment_adress++].position = sf::Vector2f(x_near-size_thick, y_near-size_thick); //for top-left corner
                    m_border[increment_adress++].position = sf::Vector2f(x_far+size_thick, y_near-size_thick);  //for top-right corner
                    m_border[increment_adress++].position = sf::Vector2f(x_far+size_thick, y_far+size_thick);   //for bottom-right corner
                    m_border[increment_adress++].position = sf::Vector2f(x_near-size_thick, y_far+size_thick);  //for bottom-left corner
                    m_border[increment_adress++].position = sf::Vector2f(x_near-size_thick, y_near-size_thick); //again for top-left, close the way
            }

            for(int i = 0; i < increment_adress; ++i)           //set color for border
                m_border[i].color = sf::Color(200, 150, 100);



}

thanks for help
« Last Edit: March 22, 2014, 03:32:11 pm by canlot »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Line issue
« Reply #1 on: March 21, 2014, 10:37:57 pm »
Add 0.5 to the lines coordinates.
Laurent Gomila - SFML developer

canlot

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Line issue
« Reply #2 on: March 21, 2014, 11:01:51 pm »
Add 0.5 to the lines coordinates.

That works, thank you  :D

But why i have to do this? I thought a line is always 1 px thick as said in tutorial: http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php under sf::Lines

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Line issue
« Reply #3 on: March 21, 2014, 11:59:14 pm »
Well it's harder to explain than to show this image:



Since the line is 0.5 on one pixel OpenGL has to decide whether it will draw it on that pixel or not. This can lead to either having two lines, a "shadow" line or none line at all.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

canlot

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Line issue
« Reply #4 on: March 22, 2014, 11:07:00 am »
Well didn't know that, and thanks for explaining.

 

anything