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);

mesh.draw(shader);

Base classes

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

Constructors, destructors, conversion operators

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

Public functions

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

Function documentation

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

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to 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.

template<UnsignedInt dimensions>
DistanceFieldVector& 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& 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& 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& 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& 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.