From 1e140f92296a04366fc7705d2af33b89c3c5877c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 5 Jul 2016 19:06:06 -0400 Subject: [PATCH] add "text" shader --- runtime/shaders/text.f.glsl | 15 +++++++++++++++ runtime/shaders/text.v.glsl | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 runtime/shaders/text.f.glsl create mode 100644 runtime/shaders/text.v.glsl diff --git a/runtime/shaders/text.f.glsl b/runtime/shaders/text.f.glsl new file mode 100644 index 0000000..c62195a --- /dev/null +++ b/runtime/shaders/text.f.glsl @@ -0,0 +1,15 @@ +#version 410 + +/* Texture coordinate: s, t */ +in vec2 texture_coord_v; + +/* Texture unit */ +uniform sampler2D texture; +uniform vec4 color; + +out vec4 frag_color; + +void main(void) +{ + frag_color = vec4(1, 1, 1, texture2D(texture, texture_coord_v).a) * color; +} diff --git a/runtime/shaders/text.v.glsl b/runtime/shaders/text.v.glsl new file mode 100644 index 0000000..1901809 --- /dev/null +++ b/runtime/shaders/text.v.glsl @@ -0,0 +1,27 @@ +#version 410 + +/* Viewport width and height */ +uniform ivec2 viewport_size; +/* Position of lower left corner of glyph */ +uniform ivec2 position; + +/* Vertex coordinates: x, y, s, t */ +layout(location = 0) in vec4 coords; + +/* Output texture coordinate: s, t */ +out vec2 texture_coord_v; + +/** + * Map coordinates such that: + * (0 .. viewport_size.[xy]) => (-1.0 .. 1.0) + */ +vec2 map_to_screen(vec2 position) +{ + return 2.0 * position / viewport_size - 1.0; +} + +void main(void) +{ + gl_Position = vec4(map_to_screen(vec2(position) + coords.xy), 0, 1); + texture_coord_v = coords.zw; +}