Skip to content

Renderable2D ​

Base class for canvas nodes that can be drawn.

Renderable2D extends Node2D with the interface the renderer needs to issue a draw call. It is the common base for all drawable 2D node types, such as Sprite and Text.

The transforms let a node draw shared geometry without rewriting vertices. A sprite draws a unit quad and supplies a transform that scales it to its size, plus a texture transform that selects its region. A node that owns geometry laid out in node space, such as text, keeps the defaults, which shift the geometry by the anchor and leave texture coordinates alone.

This class is not instantiated directly. Use one of the concrete node types, or derive from it to implement a custom drawable.

INFO

Derives from Node2D and inherits all public properties and methods.

Properties ​

anchor Vector2 ​

Normalized anchor point inside the node's bounds.

Defines which point of the bounds as reported by GetSize is placed at the node's position.

  • (0.0, 0.0) top-left corner of the bounds (default).
  • (0.5, 0.5) center of the bounds.
  • (1.0, 0.0) top-right corner, for right-aligned labels.
cpp
Vector2 anchor {0.0f, 0.0f};

color Color ​

Color multiplied with the texture. Defaults to white.

cpp
Color color {0xFFFFFFu};

Functions ​

GetGeometry() std::shared_ptr<Geometry> pure virtual ​

Returns the geometry used to draw this node.

cpp
virtual std::shared_ptr<Geometry> Renderable2D::GetGeometry()=0;

GetGeometryTransform() Matrix3 virtual ​

Returns the transform that maps geometry vertices into node space.

The default shifts the geometry by the anchor. Nodes that draw shared geometry compose their own scaling.

cpp
virtual Matrix3 Renderable2D::GetGeometryTransform() const;

GetNodeType() Node2D::Type virtual ​

Identifies this node as Node2D::Type::Renderable.

cpp
Type vglx::Renderable2D::GetNodeType() const override;

GetSize() Vector2 pure virtual ​

Returns the node's size in canvas units before scaling.

The anchor is measured against this size. Returns zero when there is nothing to draw.

cpp
virtual Vector2 Renderable2D::GetSize() const=0;

GetTexture() std::shared_ptr<Texture2D> pure virtual ​

Returns the texture sampled by the geometry or nullptr when there's nothing to draw.

cpp
virtual std::shared_ptr<Texture2D> Renderable2D::GetTexture() const=0;

GetTextureTransform() Matrix3 virtual ​

Returns the transform that maps geometry texture coordinates into the texture.

cpp
virtual Matrix3 Renderable2D::GetTextureTransform() const;

IsRenderable() bool virtual ​

Returns true, identifying this node as renderable.

cpp
bool Renderable2D::IsRenderable() const override;

Released under the MIT License.