Skip to main content

PlottingOpenGL::RectangleShaders

PlottingOpenGL::RectangleShaders

Embedded fallback shader source code for the rectangle renderer.

Attributes

Name
char const * VERTEX_SHADER
char const * FRAGMENT_SHADER
char const * BORDER_VERTEX_SHADER
Border shader (draws outline using GL_LINE_LOOP).
char const * BORDER_FRAGMENT_SHADER

Attributes Documentation

variable VERTEX_SHADER

char const  * VERTEX_SHADER = R"(
#version 410 core

// Per-vertex attributes (unit quad: [0,1] x [0,1])
layout(location = 0) in vec2 a_vertex;

// Per-instance attributes
layout(location = 1) in vec4 a_bounds;  // x, y, width, height
layout(location = 2) in vec4 a_color;

uniform mat4 u_mvp_matrix;

out vec4 v_color;

void main() {
    // Scale and translate unit quad to rectangle bounds
    // a_bounds.xy = bottom-left corner, a_bounds.zw = width, height
    vec2 worldPos = a_bounds.xy + a_vertex * a_bounds.zw;
    gl_Position = u_mvp_matrix * vec4(worldPos, 0.0, 1.0);
    v_color = a_color;
}
)";

variable FRAGMENT_SHADER

char const  * FRAGMENT_SHADER = R"(
#version 410 core

in vec4 v_color;

out vec4 FragColor;

void main() {
    FragColor = v_color;
}
)";

variable BORDER_VERTEX_SHADER

char const  * BORDER_VERTEX_SHADER = R"(
#version 410 core

// Per-vertex attributes (unit quad corners)
layout(location = 0) in vec2 a_vertex;

// Per-instance attributes
layout(location = 1) in vec4 a_bounds;

uniform mat4 u_mvp_matrix;

void main() {
    vec2 worldPos = a_bounds.xy + a_vertex * a_bounds.zw;
    gl_Position = u_mvp_matrix * vec4(worldPos, 0.0, 1.0);
}
)";

Border shader (draws outline using GL_LINE_LOOP).

variable BORDER_FRAGMENT_SHADER

char const  * BORDER_FRAGMENT_SHADER = R"(
#version 410 core

uniform vec4 u_border_color;

out vec4 FragColor;

void main() {
    FragColor = u_border_color;
}
)";

Updated on 2026-11-13 at 20:25:41 +0000