class SF::VertexArray
- SF::VertexArray
- Reference
- Object
Overview
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
Defined in:
graphics/obj.crConstructors
-
.new(type : PrimitiveType, vertex_count : Int = 0)
Construct the vertex array with a type and an initial number of vertices
-
.new
Default constructor
Instance Method Summary
-
#[](index : Int) : Vertex
Get the vertex by its index
-
#[]=(index : Int, value : Vertex)
Set the vertex by its index
-
#append(vertex : Vertex)
Add a vertex to the array
-
#bounds : FloatRect
Compute the bounding rectangle of the vertex array
-
#clear
Clear the vertex array
-
#dup : VertexArray
Returns a shallow copy of this object.
- #finalize
-
#primitive_type : PrimitiveType
Get the type of primitives drawn by the vertex array
-
#primitive_type=(type : PrimitiveType)
Set the type of primitives to draw
-
#resize(vertex_count : Int)
Resize the vertex array
-
#vertex_count : Int32
Return the vertex count
Instance methods inherited from module SF::Drawable
draw(target : RenderTarget, states : RenderStates)
draw
Constructor Detail
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
Instance Method Detail
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
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
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
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.
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self
into it.
Get the type of primitives drawn by the vertex array
Returns: Primitive 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
. -
type - Type of primitive
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)