Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Public Attributes | List of all members
gf::Vertex Struct Reference

A point associated with a color and a texture coordinate. More...

#include <gf/Vertex.h>

Public Attributes

Vector2f position
 Position of the vertex in world coordinates. More...
 
Color4f color = Color::White
 Color of the vertex (default: white) More...
 
Vector2f texCoords = Vector2f{ 0.0f, 0.0f }
 Coordinates of the texture. More...
 

Detailed Description

A point associated with a color and a texture coordinate.

gf::Vertex represents the association between a position in the world, a color and texture coordinates.

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

If you use the graphical entities of gf (sprite, shape), you won't have to deal with vertices directly. But if you want to define your own 2D entities, using vertices will allow you to get maximum performances.

The texture coordinates are in the \( [0, 1] \) range. \( (0,0) \) is the top-left of the texture while \( (1,1) \) is the bottom right of the texture. If a coordinate is outside the \( [0, 1] \) range, the texture is clamped or repeated (see Texture::setRepeated).

Example:

// define a triangle
gf::Vertex triangle[3];
triangle[0].position = { 0.0f, 0.5f };
triangle[0].color = gf::Color::Red;
triangle[1].position = { 0.5f, -0.5f };
triangle[1].color = gf::Color::Green;
triangle[2].position = { -0.5f, -0.5f };
triangle[2].color = gf::Color::Yellow;
// and draw it
renderer.draw(triangle, 3, gf::PrimitiveType::Triangles);
See also
gf::PrimitiveType, gf::RenderTarget::draw

Member Data Documentation

Color4f gf::Vertex::color = Color::White

Color of the vertex (default: white)

Vector2f gf::Vertex::position

Position of the vertex in world coordinates.

Vector2f gf::Vertex::texCoords = Vector2f{ 0.0f, 0.0f }

Coordinates of the texture.