From 46f84744afa3cd586450e3f49acdfcf09e3c7b57 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 29 Aug 2022 08:04:55 +0200 Subject: Add rudimentary input mirroring --- src/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 7a8b6e7..32be6c7 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,10 @@ #include "shorthand.h" #include "bd-font.c" -#define TEXT_OVERLAY_SIZE 5 +#define TEXT_OVERLAY_SIZE 4 + +static char text[2048]; +static u32 text_n = 0; // // Callbacks. @@ -29,6 +32,12 @@ glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mod } } +void +glfw_text_callback(GLFWwindow* window, unsigned int codepoint) { + (void)window; + text[text_n++] = codepoint; +} + // Letter for a the monospace text overlay layer. struct Letter { f32 x; @@ -304,6 +313,7 @@ void setup_callbacks(Context *ctx) { glfwSetErrorCallback(glfw_error_callback); glfwSetKeyCallback(ctx->window, glfw_key_callback); + glfwSetCharCallback(ctx->window, glfw_text_callback); } void @@ -355,7 +365,7 @@ add_text(Context *ctx, char *txt) { void update_text(Context *ctx) { clear_text(ctx); - add_text(ctx, "hello world!"); + add_text(ctx, text); glBindBuffer(GL_ARRAY_BUFFER, ctx->text_overlay.vbo); glBufferData(GL_ARRAY_BUFFER, -- cgit v1.2.1