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

Author Topic: Extract Triangles  (Read 776 times)

0 Members and 1 Guest are viewing this topic.


  • Hero Member
  • *****
  • Posts: 3339
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Extract Triangles
« on: November 24, 2023, 06:11:46 pm »
The different (solid) primitive types are useful for individual objects but, sometimes, we need independent triangles, especially if we want to have multiple (separate) shapes in a single vertex array.

Presenting to you, Extract Triangles!

Extract Triangles does exactly that; it extracts individual triangles from the other primitive types.

Basically, it's this:
sf::VertexArray triangleFan(sf::PrimitiveType::TriangleFan);
// set up vertices for triangle fan
sf::VertexArray independentTriangles{ extractTriangles::vertexArrayFrom(triangleFan) };

Simple, huh? 8)

It can also work with just vertices (i.e. std::vector<sf::Vertex>) as well as convert between the two types and - for some reason - can also create vertex buffers from either of those!

For more information as well as the code, visit the SFML wiki and/or the GitHub repository listed below.

Wiki page:

GitHub repository (it's a part of SfmlSnippets):

There is also an example showing it in action included in the repository and also on the wiki page.

Feel free to ask any questions or make any comments.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
 *Hapaxia Links*