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

Author Topic: [SOLVED] Unexpected behavior when coloring sf::Vertex  (Read 2048 times)

0 Members and 1 Guest are viewing this topic.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
[SOLVED] Unexpected behavior when coloring sf::Vertex
« 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!
« Last Edit: January 26, 2015, 08:26:59 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Unexpected behavior when coloring sf::Vertex
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Unexpected behavior when coloring sf::Vertex
« Reply #2 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! :)
« Last Edit: October 01, 2014, 07:37:29 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Unexpected behavior when coloring sf::Vertex
« Reply #3 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)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Unexpected behavior when coloring sf::Vertex
« Reply #4 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)
« Last Edit: October 02, 2014, 08:38:20 am by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Unexpected behavior when coloring sf::Vertex
« Reply #5 on: October 02, 2014, 06:42:34 pm »
Triangulation ftw!
Explicit triangulation ftw!  ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*