template<UnsignedInt dimensions>
Magnum::Shaders::DistanceFieldVector class

Distance field vector shader.

Renders vector graphics in a form of signed distance field. See TextureTools::DistanceField for more information. Note that the final rendered outlook will greatly depend on radius of input distance field and value passed to setSmoothness(). You need to provide Position and TextureCoordinates attributes in your triangle mesh and call at least bindVectorTexture(). By default, the shader renders the distance field texture with a white color in an identity transformation, use setTransformationProjectionMatrix(), setColor() and others to configure the shader.

Image

Example usage

Common mesh setup:

struct Vertex {
    Vector2 position;
    Vector2 textureCoordinates;
};
Vertex data[60]{
    // ...
};

GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);

GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
    Shaders::DistanceFieldVector2D::Position{},
    Shaders::DistanceFieldVector2D::TextureCoordinates{})
    // ...
    ;

Common rendering setup:

Matrix3 transformationMatrix, projectionMatrix;
GL::Texture2D texture;

Shaders::DistanceFieldVector2D shader;
shader.setColor(0x2f83cc_rgbf)
    .setOutlineColor(0xdcdcdc_rgbf)
    .setOutlineRange(0.6f, 0.4f)
    .bindVectorTexture(texture)
    .setTransformationProjectionMatrix(projectionMatrix*transformationMatrix)
    .draw(mesh);

Base classes

template<UnsignedInt dimensions>
class AbstractVector
Base for vector shaders.

Public types

enum class Flag: UnsignedByte { TextureTransformation = 1 << 0 new in Git master } new in Git master
Flag.
using Flags = Containers::EnumSet<Flag> new in Git master
Flags.

Constructors, destructors, conversion operators

DistanceFieldVector(Flags flags = {}) explicit
Constructor.
DistanceFieldVector(NoCreateT) explicit noexcept
Construct without creating the underlying OpenGL object.
DistanceFieldVector(const DistanceFieldVector<dimensions>&) deleted
Copying is not allowed.
DistanceFieldVector(DistanceFieldVector<dimensions>&&) defaulted noexcept
Move constructor.

Public functions

auto operator=(const DistanceFieldVector<dimensions>&) -> DistanceFieldVector<dimensions>& deleted
Copying is not allowed.
auto operator=(DistanceFieldVector<dimensions>&&) -> DistanceFieldVector<dimensions>& defaulted noexcept
Move assignment.
auto flags() const -> Flags new in Git master
Flags.
auto setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) -> DistanceFieldVector<dimensions>&
Set transformation and projection matrix.
auto setTextureMatrix(const Matrix3& matrix) -> DistanceFieldVector<dimensions>& new in Git master
Set texture coordinate transformation matrix.
auto setColor(const Color4& color) -> DistanceFieldVector<dimensions>&
Set fill color.
auto setOutlineColor(const Color4& color) -> DistanceFieldVector<dimensions>&
Set outline color.
auto setOutlineRange(Float start, Float end) -> DistanceFieldVector<dimensions>&
Set outline range.
auto setSmoothness(Float value) -> DistanceFieldVector<dimensions>&
Set smoothness radius.

Enum documentation

template<UnsignedInt dimensions>
enum class Magnum::Shaders::DistanceFieldVector<dimensions>::Flag: UnsignedByte new in Git master

Flag.

Enumerators
TextureTransformation new in Git master

Enable texture coordinate transformation.

Typedef documentation

template<UnsignedInt dimensions>
typedef Containers::EnumSet<Flag> Magnum::Shaders::DistanceFieldVector<dimensions>::Flags new in Git master

Flags.

Function documentation

template<UnsignedInt dimensions>
Magnum::Shaders::DistanceFieldVector<dimensions>::DistanceFieldVector(Flags flags = {}) explicit

Constructor.

Parameters
flags Flags

template<UnsignedInt dimensions>
Magnum::Shaders::DistanceFieldVector<dimensions>::DistanceFieldVector(NoCreateT) explicit noexcept

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to a moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active. However note that this is a low-level and a potentially dangerous API, see the documentation of NoCreate for alternatives.

template<UnsignedInt dimensions>
DistanceFieldVector<dimensions>& Magnum::Shaders::DistanceFieldVector<dimensions>::setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix)

Set transformation and projection matrix.

Returns Reference to self (for method chaining)

Initial value is an identity matrix.

template<UnsignedInt dimensions>
DistanceFieldVector<dimensions>& Magnum::Shaders::DistanceFieldVector<dimensions>::setTextureMatrix(const Matrix3& matrix) new in Git master

Set texture coordinate transformation matrix.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::TextureTransformation enabled. Initial value is an identity matrix.

template<UnsignedInt dimensions>
DistanceFieldVector<dimensions>& Magnum::Shaders::DistanceFieldVector<dimensions>::setColor(const Color4& color)

Set fill color.

Returns Reference to self (for method chaining)

Initial value is 0xffffffff_rgbaf.

template<UnsignedInt dimensions>
DistanceFieldVector<dimensions>& Magnum::Shaders::DistanceFieldVector<dimensions>::setOutlineColor(const Color4& color)

Set outline color.

Returns Reference to self (for method chaining)

Initial value is 0x00000000_rgbaf and the outline is not drawn — see setOutlineRange() for more information.

template<UnsignedInt dimensions>
DistanceFieldVector<dimensions>& Magnum::Shaders::DistanceFieldVector<dimensions>::setOutlineRange(Float start, Float end)

Set outline range.

Returns Reference to self (for method chaining)

The start parameter describes where fill ends and possible outline starts. Initial value is 0.5f, larger values will make the vector art look thinner, smaller will make it look thicker.

The end parameter describes where outline ends. If set to value larger than start the outline is not drawn. Initial value is 1.0f.

template<UnsignedInt dimensions>
DistanceFieldVector<dimensions>& Magnum::Shaders::DistanceFieldVector<dimensions>::setSmoothness(Float value)

Set smoothness radius.

Returns Reference to self (for method chaining)

Larger values will make edges look less aliased (but blurry), smaller values will make them look more crisp (but possibly aliased). Initial value is 0.04f.

template<UnsignedInt dimensions> template<UnsignedInt dimensions>
Debug& operator<<(Debug& debug, DistanceFieldVector<dimensions>::Flag value)

Debug output operator.

template<UnsignedInt dimensions> template<UnsignedInt dimensions>
Debug& operator<<(Debug& debug, DistanceFieldVector<dimensions>::Flags value)

Debug output operator.