SFML 2.6.2

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | List of all members
sf::VertexArray Class Reference
Graphics module

Define a set of one or more 2D primitives. More...

`#include <SFML/Graphics/VertexArray.hpp>`

Inheritance diagram for sf::VertexArray:

## Public Member Functions

| VertexArray ()
| Default constructor.
| VertexArray (PrimitiveType type, std::size_t vertexCount=0)
| Construct the vertex array with a type and an initial number of vertices.
std::size_t | getVertexCount () const
| Return the vertex count.
Vertex & | operator[] (std::size_t index)
| Get a read-write access to a vertex by its index.
const Vertex & | operator[] (std::size_t index) const
| Get a read-only access to a vertex by its index.
void | clear ()
| Clear the vertex array.
void | resize (std::size_t vertexCount)
| Resize the vertex array.
void | append (const Vertex &vertex)
| Add a vertex to the array.
void | setPrimitiveType (PrimitiveType type)
| Set the type of primitives to draw.
PrimitiveType | getPrimitiveType () const
| Get the type of primitives drawn by the vertex array.
FloatRect | getBounds () const
| Compute the bounding rectangle of the vertex array.

## Detailed Description

Define a set of one or more 2D primitives.

sf::VertexArray is a very simple wrapper around a dynamic array of vertices and a primitives type.

It inherits sf::Drawable, but unlike other drawables it is not transformable.

Example:

sf::VertexArray lines(sf::LineStrip, 4);
lines[0].position = sf::Vector2f(10, 0);
lines[1].position = sf::Vector2f(20, 0);
lines[2].position = sf::Vector2f(30, 5);
lines[3].position = sf::Vector2f(40, 2);
window.draw(lines);
sf::VertexArray
Define a set of one or more 2D primitives.
Definition VertexArray.hpp:46
sf::LineStrip
@ LineStrip
List of connected lines, a point uses the previous point to form a line.
Definition PrimitiveType.hpp:43
sf::Vector2f
Vector2< float > Vector2f
Definition Vector2.hpp:255

See also
  sf::Vertex

Definition at line 45 of file VertexArray.hpp.

## Constructor & Destructor Documentation

## ◆ VertexArray() [1/2]

sf::VertexArray::VertexArray | ( |  | ) |

Default constructor.

Creates an empty vertex array.

## ◆ VertexArray() [2/2]

sf::VertexArray::VertexArray | ( | PrimitiveType | type,
|  | std::size_t | vertexCount = `0`
| ) |  |

explicit

Construct the vertex array with a type and an initial number of vertices.

Parameters

  type | Type of primitives
  vertexCount | Initial number of vertices in the array

## Member Function Documentation

## ◆ append()

void sf::VertexArray::append | ( | const Vertex & | vertex | ) |

Add a vertex to the array.

Parameters

  vertex | Vertex to add

## ◆ clear()

void sf::VertexArray::clear | ( |  | ) |

Clear the vertex array.

This function removes all the vertices from the array. It doesn't deallocate the corresponding memory, so that adding new vertices after clearing doesn't involve reallocating all the memory.

## ◆ getBounds()

FloatRect sf::VertexArray::getBounds | ( |  | ) | const

Compute the bounding rectangle of the vertex array.

This function returns the minimal axis-aligned rectangle that contains all the vertices of the array.

Returns
  Bounding rectangle of the vertex array

## ◆ getPrimitiveType()

PrimitiveType sf::VertexArray::getPrimitiveType | ( |  | ) | const

Get the type of primitives drawn by the vertex array.

Returns
  Primitive type

## ◆ getVertexCount()

std::size_t sf::VertexArray::getVertexCount | ( |  | ) | const

Return the vertex count.

Returns
  Number of vertices in the array

## ◆ operator[]() [1/2]

Vertex & sf::VertexArray::operator[] | ( | std::size_t | index | ) |

Get a read-write access to a vertex by its index.

This function doesn't check index, it must be in range [0, getVertexCount() - 1]. The behavior is undefined otherwise.

Parameters

  index | Index of the vertex to get

Returns
  Reference to the index-th vertex

See also
  getVertexCount

## ◆ operator[]() [2/2]

const Vertex & sf::VertexArray::operator[] | ( | std::size_t | index | ) | const

Get a read-only access to a vertex by its index.

This function doesn't check index, it must be in range [0, getVertexCount() - 1]. The behavior is undefined otherwise.

Parameters

  index | Index of the vertex to get

Returns
  Const reference to the index-th vertex

See also
  getVertexCount

## ◆ resize()

void sf::VertexArray::resize | ( | std::size_t | vertexCount | ) |

Resize the vertex array.

If vertexCount is greater than the current size, the previous vertices are kept and new (default-constructed) vertices are added. If vertexCount is less than the current size, existing vertices are removed from the array.

Parameters

  vertexCount | New size of the array (number of vertices)

## ◆ setPrimitiveType()

void sf::VertexArray::setPrimitiveType | ( | PrimitiveType | type | ) |

Set the type of primitives to draw.

This function defines how the vertices must be interpreted when it's time to draw them:

- As points
- As lines
- As triangles
- As quads The default primitive type is sf::Points.

Parameters

  type | Type of primitive

The documentation for this class was generated from the following file:

- VertexArray.hpp