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

Author Topic: Extract Triangles  (Read 8356 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3415
  • 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!
(updated to use SFML 3!)

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:
https://github.com/SFML/SFML/wiki/Source:-Triangles-Extractor

GitHub repository (it's a part of SfmlSnippets):
https://github.com/Hapaxia/SfmlSnippets/tree/master/TrianglesExtractor

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.
« Last Edit: March 01, 2025, 06:59:49 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*