summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-08-29 07:11:23 +0200
committerBad Diode <bd@badd10de.dev>2022-08-29 07:11:23 +0200
commit94c36fb2f2c8f1c90752df4df96f7f65d7ade9b0 (patch)
treebaa2a56417d6ca58ce300ee30bd34701aada012c
parent6218601074e7070ccd5ded69a79f313d83a17cf6 (diff)
downloadogl-monotext-94c36fb2f2c8f1c90752df4df96f7f65d7ade9b0.tar.gz
ogl-monotext-94c36fb2f2c8f1c90752df4df96f7f65d7ade9b0.zip
Add working monospace text indexing to shader
-rw-r--r--src/main.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 2a901a3..543ef86 100644
--- a/src/main.c
+++ b/src/main.c
@@ -216,9 +216,9 @@ render(Context *ctx) {
216 f32 idx; 216 f32 idx;
217 }; 217 };
218 struct Letter letters[] = { 218 struct Letter letters[] = {
219 {-0.25, 0.0, 0}, 219 {0, 0.0, 0},
220 {0.0, 0.0, 1}, 220 {1, 0.0, 1},
221 {0.25, 0.0, 2}, 221 {2, 0.0, 2},
222 }; 222 };
223 u32 offset_vbo; 223 u32 offset_vbo;
224 glGenBuffers(1, &offset_vbo); 224 glGenBuffers(1, &offset_vbo);
@@ -259,6 +259,7 @@ render(Context *ctx) {
259 glBindBuffer(GL_ARRAY_BUFFER, 0); 259 glBindBuffer(GL_ARRAY_BUFFER, 0);
260 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 260 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
261 261
262 // TODO: Store the shaders as separate files for easier editing.
262 const char* vert_src = 263 const char* vert_src =
263"#version 330 core\n" 264"#version 330 core\n"
264"layout (location = 0) in vec2 position;\n" 265"layout (location = 0) in vec2 position;\n"
@@ -266,11 +267,25 @@ render(Context *ctx) {
266"layout (location = 2) in vec3 offset;\n" 267"layout (location = 2) in vec3 offset;\n"
267"out vec2 tex;\n" 268"out vec2 tex;\n"
268"void main() {\n" 269"void main() {\n"
269" float idx = offset.z;\n" 270// TODO: Uniforms
271" float w = 800;\n"
272" float h = 600;\n"
273" float size = 5;\n"
270" float N = 3;\n" 274" float N = 3;\n"
275
276" float idx = offset.z;\n"
271" float m = 1.0 / N;\n" 277" float m = 1.0 / N;\n"
272" float k = m * idx;\n" 278" float k = m * idx;\n"
273" gl_Position = vec4(position / 8 + offset.xy, 0.0, 1.0);\n" 279// TODO: Only 8x8 monospace fonts for now
280" float font_w = 8;\n"
281" float font_h = 8;\n"
282// NOTE: This makes sures that the fonts have the right size.
283" vec2 scalar = vec2(font_w / w, font_h / h) * size;\n"
284" vec2 pos = tex_coords * scalar;\n"
285" pos += vec2(0.0, 1.0 - scalar.y);\n"
286" pos += scalar * offset.xy;\n"
287" pos = mix(vec2(-1.0), vec2(1.0), pos);\n"
288" gl_Position = vec4(pos, 0.0, 1.0);\n"
274" tex = tex_coords * vec2(m, 1.0) + vec2(k, 0.0);\n" 289" tex = tex_coords * vec2(m, 1.0) + vec2(k, 0.0);\n"
275"}"; 290"}";
276 291