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

Vertex color shader.

Draws vertex-colored mesh. You need to provide Position and Color attributes in your triangle mesh. By default, the shader renders the mesh in an identity transformation. Use setTransformationProjectionMatrix() to configure the shader.


Example usage

Common mesh setup. The shader accepts either three- or four-component color attribute, use either Color3 or Color4 to specify which one you use.

struct Vertex {
    Vector3 position;
    Color3 color;
Vertex data[60]{
    // ...

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

GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,

Common rendering setup:

Matrix4 transformationMatrix = Matrix4::translation(Vector3::zAxis(-5.0f));
Matrix4 projectionMatrix = Matrix4::perspectiveProjection(35.0_degf, 1.0f, 0.001f, 100.0f);

Shaders::VertexColor3D shader;


Base classes

class Magnum::GL::AbstractShaderProgram
Base for shader program implementations.

Public types

using Position = Generic<dimensions>::Position
Vertex position.
using Color3 = Generic<dimensions>::Color3
Three-component vertex color.
using Color4 = Generic<dimensions>::Color4
Four-component vertex color.
using Color = Generic<dimensions>::Color deprecated
Vertex color.

Constructors, destructors, conversion operators

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

Public functions

auto operator=(const VertexColor<dimensions>&) -> VertexColor<dimensions>& deleted
Copying is not allowed.
auto operator=(VertexColor<dimensions>&&) noexcept -> VertexColor<dimensions>& defaulted
Move assignment.
auto setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) -> VertexColor<dimensions>&
Set transformation and projection matrix.

Typedef documentation

template<UnsignedInt dimensions>
typedef Generic<dimensions>::Position Magnum::Shaders::VertexColor<dimensions>::Position

Vertex position.

Generic attribute, Vector2 in 2D Vector3 in 3D.

template<UnsignedInt dimensions>
typedef Generic<dimensions>::Color3 Magnum::Shaders::VertexColor<dimensions>::Color3

Three-component vertex color.

Generic attribute, Magnum::Color3. Use either this or the Color4 attribute.

template<UnsignedInt dimensions>
typedef Generic<dimensions>::Color4 Magnum::Shaders::VertexColor<dimensions>::Color4

Four-component vertex color.

Generic attribute, Magnum::Color4. Use either this or the Color3 attribute.

template<UnsignedInt dimensions>
typedef Generic<dimensions>::Color Magnum::Shaders::VertexColor<dimensions>::Color

Vertex color.

Function documentation

template<UnsignedInt dimensions>
Magnum::Shaders::VertexColor<dimensions>::VertexColor(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>
VertexColor<dimensions>& Magnum::Shaders::VertexColor<dimensions>::setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix)

Set transformation and projection matrix.

Returns Reference to self (for method chaining)

Default is an identity matrix.