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

Author Topic: Tight shapes have incorrect outlines  (Read 4251 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Tight shapes have incorrect outlines
« on: August 10, 2012, 09:45:16 pm »
If a convex SFML shape covers a very small area, the edges are drawn outside the shape. I don't know whether this is an OpenGL limitation or a bug internal to SFML.

Minimal and complete example:
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Shape Bug");

        sf::ConvexShape shape(3);
        shape.setPoint(0, sf::Vector2f(0.f, 0.f));
        shape.setPoint(1, sf::Vector2f(0.1f, 100.f));
        shape.setPoint(2, sf::Vector2f(0.f, 200.f));

        shape.setPosition(100.f, 100.f);
        shape.setFillColor(sf::Color::Transparent);
        shape.setOutlineThickness(1.f);
        shape.setOutlineColor(sf::Color::Yellow);

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::KeyPressed || event.type == sf::Event::Closed)
                                return 0;
                }

                window.clear();
                window.draw(shape);
                window.display();
        }
}
« Last Edit: August 10, 2012, 10:09:07 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Tight shapes have incorrect outlines
« Reply #1 on: August 10, 2012, 10:11:01 pm »
This can't be an OpenGL limitation otherwise we wouldn't be able to have nice borders in SFGUI either ;).
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Tight shapes have incorrect outlines
« Reply #2 on: August 10, 2012, 10:56:55 pm »
I didn't mean it were generally impossible, my thor::ConcaveShape class works also. But maybe the current approach with triangle strips is problematic...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Tight shapes have incorrect outlines
« Reply #3 on: August 10, 2012, 11:23:58 pm »
Sorry but what's the problem? I tried your minimal example and it looks ok. The outline expands far on the Y axis, but this is the expected behaviour. Is that what you wanted to point out?
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Tight shapes have incorrect outlines
« Reply #4 on: August 10, 2012, 11:28:10 pm »
Yes. Why is it expected that the edges are longer than the distance between the points? I can't imagine a use case where this is intentional.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Tight shapes have incorrect outlines
« Reply #5 on: August 10, 2012, 11:35:53 pm »
My algorithm to extrude the outline ensures that its thickness remains constant (otherwise it would look really weird). So when two edges are almost parallel, the outline intersects much further than the shape's point.

The solution would be to implement a different joint algorithm ("bevel" or "round").
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Tight shapes have incorrect outlines
« Reply #6 on: August 11, 2012, 11:16:03 am »
Ah indeed, it's a consequence of the sharp corners. I don't know whether people prefer having exactly straight edges or an outline that doesn't exceed the shape. What do other users think?

If there is disagreement, one possibility is also to let the user choose the joint algorithm by adding a corresponding method in the future...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Tight shapes have incorrect outlines
« Reply #7 on: August 11, 2012, 11:46:04 am »
This is really only a problem in very specific cases where the outline of a shape is in the same order of magnitude as the shape itself (or even larger as in your example). In "normal" cases where the outline really is nothing more than an outline and much smaller than the shape area itself this isn't really a problem so I would call this one of those "usage quirks".
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything