Skip to content

class SF::VertexArray
inherits Reference #

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 includes SF::Drawable, but unlike other drawables it is not transformable.

Example:

lines = SF::VertexArray.new(SF::LineStrip, 4)
lines[0] = SF::Vertex.new(SF.vector2f(10, 0))
lines[1] = SF::Vertex.new(SF.vector2f(20, 0))
lines[2] = SF::Vertex.new(SF.vector2f(30, 5))
lines[3] = SF::Vertex.new(SF.vector2f(40, 2))

window.draw(lines)

See also: SF::Vertex

Included modules

SF::Drawable

Constructors#

.new(type : PrimitiveType, vertex_count : Int = 0)#

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

  • type - Type of primitives
  • vertex_count - Initial number of vertices in the array
View source

.new#

Default constructor

Creates an empty vertex array.

View source

Methods#

#[](index : Int) : Vertex#

Get the vertex by its index

This method doesn't check index, it must be in range 0 ... vertex_count. The behavior is undefined otherwise.

  • index - Index of the vertex to get

Returns: The index-th vertex

See also: vertex_count

View source

#[]=(index : Int, value : Vertex)#

Set the vertex by its index

This method doesn't check index, it must be in range 0 ... vertex_count. The behavior is undefined otherwise.

  • index - Index of the vertex to set

See also: vertex_count

View source

#append(vertex : Vertex)#

Add a vertex to the array

  • vertex - Vertex to add
View source

#bounds : FloatRect#

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

View source

#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.

View source

#dup : VertexArray#

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.

View source

#finalize#

View source

#primitive_type : PrimitiveType#

Get the type of primitives drawn by the vertex array

Returns: Primitive type

View source

#primitive_type=(type : PrimitiveType)#

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.

  • type - Type of primitive

View source

#resize(vertex_count : Int)#

Resize the vertex array

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

  • vertex_count - New size of the array (number of vertices)
View source

#vertex_count : Int32#

Return the vertex count

Returns: Number of vertices in the array

View source