Skip to content
TechnologicalTurtle edited this page Jul 20, 2026 · 1 revision

Shape generators

Shape generators are functions found in Shapes namespace, which can generate shapes of various kinds, including rectangles, polygons, regular polygons and lines. They are mainly used in LibGui::Object constructors.

Note

In code examples below, I 'use' using namespace LibGui::Shapes to avoid repeating LibGui::Shapes everywhere.

Rectangles

Shape Rectangle(const Vec2 anchor = {0.5f, 0.5f})
Generates square around anchor. To change size use MyObject.scale = {[new size]};

Polygons

Shape Polygon(std::vector<Vertex>& vertices)
Creates polygon from your vertices.

Regular polygons

Shape RegularPolygon(int verticesCount)
Generates regular polygon with verticesCount count of vertices. To set radius use MyObject.scale = {[radius], [radius]}; as this function can't set it itself.

Simple lines

Shape LineStrip(const std::vector<Vec2>& points)
Creates line shape from points, use with UniformFlag_RenderAsLine, as this function can't set it itself.

Complex lines

Shape LineStrip(std::vector<Vertex> points)
Creates line shape from points, use with UniformFlag_RenderAsLine, as this function can't set it itself.

Entirely custom shapes

If you want entirely custom shape with your own vertices and indices, you can just put these two std::vectors into std::pair as LibGui::Shapes::Shape is typedef of std::pair<std::vector<LibGui::Vertex>, std::vector<unsigned int>>:

// vertices
std::vector vertices = {
   LibGui::Vertex{{0, 0}, Color::Red},
   LibGui::Vertex{{1, 0}, Color::Green},
   LibGui::Vertex{{0, 1}, Color::Blue}
};

// indices aka in what order to render vertices
// in this easy example, they are unnecessary, but in bigger shapes, they help avoiding duplicates and make the job easier
std::vector<unsigned int> indices = {0, 1, 2};

// and our shape:
LibGui::Shapes::Shape my_shape{vertices, indices};

Clone this wiki locally