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

Author Topic: VertexArray and TriangleFans  (Read 2167 times)

0 Members and 1 Guest are viewing this topic.

Garwin

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
VertexArray and TriangleFans
« on: August 01, 2022, 10:59:27 pm »
I am trying to do fireworks.
My idea is to draw circle shapes even on tails. However this means just too many shapes and too many drawing calls that sometimes fps drops just too low.

So I was thinking using vertex arrays and triangle fans so using 1 call will draw me firework with the whole tail.
note: I do not want to use lines or rectangles as I cannot get gradient I want.

Is it possible to use vertex array (or own container as deque or vector) for triangle fans and if so how it can  be done, how can I tell how many points is single triangle fan and how many it should draw from the array.

So far it seems to me that it is possible only for same primitives as points, lines and triangles or is there a way to achive it with more complex primitives?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: VertexArray and TriangleFans
« Reply #1 on: August 02, 2022, 12:46:21 am »
Yes, you can just use a std::vector<sf::Vertex> and draw that to the window.
However you can't mix the primitive type per vertex "array", so it would need to all be triangle fans.

See also: https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#primitive-types
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Garwin

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: VertexArray and TriangleFans
« Reply #2 on: August 02, 2022, 07:24:40 am »
Yes, you can just use a std::vector<sf::Vertex> and draw that to the window.
However you can't mix the primitive type per vertex "array", so it would need to all be triangle fans.

See also: https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#primitive-types

This I have already tried and I have no issue drawing a single triangle fan however I cannot draw more triangle fans with one vertex array.

I have a triangle fan with 10 points (1 center, 8 points for the circle and 1 additional point at end of the circle).

I append vertex array to include several triangle fans but when I tried to draw it, it does draw only the first one.

m_game->m_window.draw(&m_tail[0], m_pointCount, sf::TriangleFan);

m_pointCount is 10 (one single triangle fan)

This just does not work (m_tail has dozens of points as it has dozens of triangle fans).


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: VertexArray and TriangleFans
« Reply #3 on: August 02, 2022, 08:08:11 am »
Aha, now I understand your question.

Yeah, it's not possible to have disjoint groups of triangle fans in a single vertex array, but the additional vertex count shouldn't lead to dramatic slow downs when using pure triangles.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Garwin

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: VertexArray and TriangleFans
« Reply #4 on: August 02, 2022, 08:13:30 am »
Thanks a lot, now I understand and you confirm me, what I have fought, only primitives points, lines and triangles can have multiple ones in a single array, otherwise it needs to have

I have already implemented it through triangles, it is not so difficult. I have better performance than using sf::CircleShape but still will need some optimization. I would probably try std container (deque) to erase already faded triangles from the container so fewer triangles need to be managed.