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

Vertex color shader.

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


This shader is equivalent to Flat with Flat::Flag::VertexColor enabled; the 3D version of this shader is equivalent to Phong with Phong::Flag::VertexColor enabled. In both cases this implementation is much simpler and thus likely also faster.

Alpha / transparency is supported by the shader implicitly, but to have it working on the framebuffer, you need to enable GL::Renderer::Feature::Blending and set up the blending function. See GL::Renderer::setBlendFunction() for details.

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

enum (anonymous): UnsignedInt { ColorOutput = Generic<dimensions>::ColorOutput }
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.

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>&&) defaulted noexcept
Move constructor.

Public functions

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

Enum documentation

template<UnsignedInt dimensions>
enum Magnum::Shaders::VertexColor<dimensions>::(anonymous): UnsignedInt


Color shader output. Generic output, present always. Expects three- or four-component floating-point or normalized buffer attachment.

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.

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 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>
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.