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

Author Topic: sf::Lines type and anti-aliasing  (Read 4931 times)

0 Members and 1 Guest are viewing this topic.

AB

  • Newbie
  • *
  • Posts: 19
    • View Profile
sf::Lines type and anti-aliasing
« on: July 21, 2013, 12:37:16 pm »
I'm using sf::VertexArray line(sf::Lines, 2) in my program and they appear as a "stretched" line that is wider than one pixel when anti-aliasing is turned on, whereas according to the documentation, they should always be one pixel wide.

Is there any way to have anti-aliasing turned on while avoiding the visual "stretching" of the lines?
« Last Edit: July 21, 2013, 03:03:20 pm by AB »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
AW: sf::Lines type and anti-aliasing
« Reply #1 on: July 21, 2013, 02:15:50 pm »
Can you provide a complete and minimal code that reproduces the problem and at best show a screenshot of the problem? :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: sf::Lines type and anti-aliasing
« Reply #2 on: July 21, 2013, 02:52:46 pm »
A screenshot would be super helpful but I feel the simple answer may be no?  I know that when working with small scale pixel art/lines/shapes that antialiasing does tend to make thin lines look thicker due to the feather/dithering whatever you want to call it that goes on as it subsamples from pixels around the edges of the line and fills in what should be blank spaces with an inbetween color/shade to make that 'smooth' look.

Good example of this is to open an image editor and try to just draw a single pixel with antialiasing on, it will draw your one pixel but also subsample from the surrounding 8 pixels around it resulting in a 3x3 shape instead of just a 1x1 pixel.  So many headaches have been caused by forgetting to turn off antialiasing in image programs that have had a fresh install.

AB

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: sf::Lines type and anti-aliasing
« Reply #3 on: July 21, 2013, 03:01:49 pm »
http://imgur.com/kOYiVcd

and a code example that reproduces it

#include <SFML/Graphics.hpp>

int main()
{
   sf::ContextSettings settings;
   settings.antialiasingLevel = 4;
   sf::RenderWindow window(sf::VideoMode(250, 250), "SFML", sf::Style::Default, settings);
   window.setVerticalSyncEnabled(true);


   sf::VertexArray line(sf::Lines, 2);
   line[0].color = sf::Color::Black;
   line[1].color = sf::Color::Black;
   line[0].position = sf::Vector2f(50, 50);
   line[1].position = sf::Vector2f(200, 50);

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

      window.clear(sf::Color::White);

      window.draw(line);

      window.display();

   }

    return 0;
}


Maximizing the window will cause the line to be rendered correctly, at least on my computer.
« Last Edit: July 21, 2013, 04:09:38 pm by AB »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: sf::Lines type and anti-aliasing
« Reply #4 on: July 21, 2013, 04:27:53 pm »
Seems like this is an overall OpenGL issue. There are some hacks that can be done with OpenGL directly or you'll have to use different methods.
When I googled a bit, I stumbled across this, but it seems very hackish.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: sf::Lines type and anti-aliasing
« Reply #5 on: July 22, 2013, 07:44:52 pm »
I might be totally wrong about this, but isn't this just the issue with lines defined in between pixel boundaries?

Ie. does writing
Code: [Select]
line[0].position = sf::Vector2f(50.5, 50.5);
line[1].position = sf::Vector2f(199.5, 50.5);

instead fix the problem?

Edit: Forgot to add that when doing this, lines need to be defined one pixel shorter (updated my example).
« Last Edit: July 22, 2013, 09:15:32 pm by Ancurio »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: sf::Lines type and anti-aliasing
« Reply #6 on: July 22, 2013, 08:12:14 pm »
I might be totally wrong about this, but isn't this just the issue with lines defined in between pixel boundaries?
Now that you say it, I remember similar issues from the past here on the forum and yes, this definitely "fixes" it! ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything