SFML community forums

Help => Graphics => Topic started by: Glocke on October 01, 2014, 06:40:54 pm

Title: [SOLVED] Unexpected behavior when coloring sf::Vertex
Post by: Glocke on October 01, 2014, 06:40:54 pm
Hi, I was working with sf::Vertex and sf::VertexArray to achieve lineare gradients over tile graphics diagonals. But I was facing something ... imho "strange behavior".

Here's my code (demo code providing my "problem"):
(click to show/hide)

I attached the tile-graphic to this post and it's original taken from http://opengameart.org/content/fancy-dungeon-tileset.

Well, the result renders "correct" for topleft and bottomright situation. But the situations at topright and bottomleft doesn't make sense to me. I want to achieve the same lineare gradient "around" the tile's diagonal - but with another direction.

Any idea what's wrong with my approach?

Kind regards & thanks in advance!
Title: Re: Unexpected behavior when coloring sf::Vertex
Post by: Hapax on October 01, 2014, 06:55:48 pm
It's because the quad is splitting into triangles differently.

Try this part:
        array[5].position = sf::Vector2f(64.f, 0.f);
        array[5].texCoords = sf::Vector2f(0.f, 0.f);
        array[5].color = sf::Color::Black;
        array[6].position = sf::Vector2f(128.f, 0.f);
        array[6].texCoords = sf::Vector2f(64.f, 0.f);
        array[6].color = sf::Color::Black;
        array[7].position = sf::Vector2f(128.f, 64.f);
        array[7].texCoords = sf::Vector2f(64.f, 64.f);
        array[7].color = sf::Color::Black;
        array[4].position = sf::Vector2f(64.f, 64.f);
        array[4].texCoords = sf::Vector2f(0.f, 64.f);
        array[4].color = sf::Color::White;

Notice the vertex renumbering.
Title: Re: Unexpected behavior when coloring sf::Vertex
Post by: Glocke on October 01, 2014, 07:16:54 pm
So it's just a matter of the right order while adding to the array? Hmm, makes sense referring to the splitting into triangles.

/EDIT: I applied the alternative order to my actual project and it works fine. Thanks! :)
Title: Re: Unexpected behavior when coloring sf::Vertex
Post by: Hapax on October 02, 2014, 12:01:40 am
You're welcome  :)

If this is the exact effect that you're looking for, wouldn't it be more simple to provide 4 triangles instead of 4 quads?
(click to show/hide)
Title: Re: Unexpected behavior when coloring sf::Vertex
Post by: Glocke on October 02, 2014, 08:01:55 am
If this is the exact effect that you're looking for, wouldn't it be more simple to provide 4 triangles instead of 4 quads?

Well, I'd need to create two vertex arrays: one using quads (for completly rendered tiles) and one using triangles (for those edges). This would really enlarge my current rendering code - but possible fix an issue, which I have with a friend's machine's rendering result (his machine seems to triangulate the quads exactly in the way I want to avoid ^^)

EDIT: I changed my rendering code to triangulate everything on its own. Else I'd have to draw-calls (on triangles and on quads). Now it's one again (triangles ^^). And my friend's machine's rendering is now as expected... Triangulation ftw!  8)
Title: Re: Unexpected behavior when coloring sf::Vertex
Post by: Hapax on October 02, 2014, 06:42:34 pm
Triangulation ftw!
Explicit triangulation ftw!  ;)