Loading...
Searching...
No Matches

Point with color and texture coordinates. More...

#include <SFML/Graphics/Vertex.hpp>

Public Attributes

Vector2f position
 2D position of the vertex
 
Color color {Color::White}
 Color of the vertex.
 
Vector2f texCoords {}
 Coordinates of the texture's pixel to map to the vertex NOLINT(readability-redundant-member-init)
 

Detailed Description

Point with color and texture coordinates.

A vertex is an improved point.

By default, the vertex color is white and texture coordinates are (0, 0).

It has a position and other extra attributes that will be used for drawing: in SFML, vertices also have a color and a pair of texture coordinates.

The vertex is the building block of drawing. Everything which is visible on screen is made of vertices. They are grouped as 2D primitives (lines, triangles, ...), and these primitives are grouped to create even more complex 2D entities such as sprites, texts, etc.

If you use the graphical entities of SFML (sprite, text, shape) you won't have to deal with vertices directly. But if you want to define your own 2D entities, such as tiled maps or particle systems, using vertices will allow you to get maximum performances.

Example:

// define a 100x100 square, red, with a 10x10 texture mapped on it
sf::Vertex vertices[]
{
{{ 0.0f, 0.0f}, sf::Color::Red, { 0.0f, 0.0f}},
{{ 0.0f, 100.0f}, sf::Color::Red, { 0.0f, 10.0f}},
{{100.0f, 100.0f}, sf::Color::Red, {10.0f, 10.0f}},
{{ 0.0f, 0.0f}, sf::Color::Red, { 0.0f, 0.0f}},
{{100.0f, 100.0f}, sf::Color::Red, {10.0f, 10.0f}},
{{100.0f, 0.0f}, sf::Color::Red, {10.0f, 0.0f}}
};
// draw it
window.draw(vertices, 6, sf::PrimitiveType::Triangles);
static const Color Red
Red predefined color.
Definition Color.hpp:84
@ Triangles
List of individual triangles.
Point with color and texture coordinates.
Definition Vertex.hpp:44

It is recommended to use aggregate initialization to create vertex objects, which initializes the members in order.

On a C++20-compliant compiler (or where supported as an extension) it is possible to use "designated initializers" to only initialize a subset of members, with the restriction of having to follow the same order in which they are defined.

Example:

// C++17 and above
sf::Vertex v0{{5.0f, 5.0f}}; // explicit 'position', implicit 'color' and 'texCoords'
sf::Vertex v1{{5.0f, 5.0f}, sf::Color::Red}; // explicit 'position' and 'color', implicit 'texCoords'
sf::Vertex v2{{5.0f, 5.0f}, sf::Color::Red, {1.0f, 1.0f}}; // everything is explicitly specified
// C++20 and above (or compilers supporting "designated initializers" as an extension)
.position{5.0f, 5.0f},
.texCoords{1.0f, 1.0f}
};

Note: Although texture coordinates are supposed to be an integer amount of pixels, their type is float because of some buggy graphics drivers that are not able to process integer coordinates correctly.

See also
sf::VertexArray

Definition at line 43 of file Vertex.hpp.

Member Data Documentation

◆ color

Color sf::Vertex::color {Color::White}

Color of the vertex.

Definition at line 49 of file Vertex.hpp.

◆ position

Vector2f sf::Vertex::position

2D position of the vertex

Definition at line 48 of file Vertex.hpp.

◆ texCoords

Vector2f sf::Vertex::texCoords {}

Coordinates of the texture's pixel to map to the vertex NOLINT(readability-redundant-member-init)

Definition at line 50 of file Vertex.hpp.


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