ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: b121b2c6f32ad34016c3748c67713a328a9fb852
Parent: c9659b840470437ade0be40050d77d8c237c72b9
Author: Randy Palamar
Date:   Thu, 20 Jun 2024 19:50:09 -0600

move font into BeamFormerCtx

Diffstat:
Mbeamformer.c | 51+++++++++++++++++++++++++++++++--------------------
Mmain.c | 2++
Mutil.h | 2++
3 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -44,22 +44,29 @@ do_compute_shader(BeamformerCtx *ctx, u32 rf_ssbo_idx, enum compute_shaders shad } static void -draw_debug_overlay(BeamformerCtx *ctx, Arena arena, Font font) +draw_debug_overlay(BeamformerCtx *ctx, Arena arena) { DrawFPS(20, 20); u32 fontsize = 32; - u32 fontspace = 4; + u32 fontspace = 1; s8 decode_txt = s8alloc(&arena, 64); s8 compute_txt = s8alloc(&arena, 64); snprintf((char *)decode_txt.data, decode_txt.len, "Decoding: %d", !!(ctx->flags & DO_DECODE)); snprintf((char *)compute_txt.data, compute_txt.len, "Compute: %d", !!(ctx->flags & DO_COMPUTE)); - v2 decode_fs = {.rl = MeasureTextEx(font, (char *)decode_txt.data, fontsize, fontspace)}; - v2 compute_fs = {.rl = MeasureTextEx(font, (char *)compute_txt.data, fontsize, fontspace)}; - v2 dpos = {.x = 20, .y = ctx->window_size.y - decode_fs.y - compute_fs.y - fontspace}; - DrawTextEx(font, (char *)decode_txt.data, dpos.rl, fontsize, fontspace, RED); + v2 decode_fs = {.rl = MeasureTextEx(ctx->font, (char *)decode_txt.data, fontsize, fontspace)}; + v2 compute_fs = {.rl = MeasureTextEx(ctx->font, (char *)compute_txt.data, fontsize, fontspace)}; + + v2 scale = {.x = 90, .y = 20 }; + v2 dpos = {.x = 20, .y = ctx->window_size.y - decode_fs.y - compute_fs.y - 20}; + v2 dposa = {.x = dpos.x + decode_fs.x / scale.x, .y = dpos.y + decode_fs.y / scale.y }; + DrawTextEx(ctx->font, (char *)decode_txt.data, dposa.rl, fontsize, fontspace, Fade(BLACK, 0.8)); + DrawTextEx(ctx->font, (char *)decode_txt.data, dpos.rl, fontsize, fontspace, RED); + dpos.y += 2 + decode_fs.y; - DrawTextEx(font, (char *)compute_txt.data, dpos.rl, fontsize, fontspace, RED); + dposa = (v2){ .x = dpos.x + compute_fs.x / scale.x, .y = dpos.y + compute_fs.y / scale.y }; + DrawTextEx(ctx->font, (char *)compute_txt.data, dposa.rl, fontsize, fontspace, Fade(BLACK, 0.8)); + DrawTextEx(ctx->font, (char *)compute_txt.data, dpos.rl, fontsize, fontspace, RED); } @@ -69,28 +76,32 @@ do_beamformer(BeamformerCtx *ctx, Arena arena, s8 rf_data) uv2 ws = ctx->window_size; f32 dt = GetFrameTime(); - static v2 pos = {.x = 32, .y = 128 }; - static v2 scale = {.x = 1.0, .y = 1.0}; - static u32 txt_idx = 0; + static v2 pos = {.x = 32, .y = 128}; + static v2 scale = {.x = 1.0, .y = 1.0}; + static u32 txt_idx = 0; static char *txt[2] = { "-_-", "^_^" }; - Font font = GetFontDefault(); - v2 fs = { .rl = MeasureTextEx(font, txt[txt_idx], 60, 6) }; + u32 fontsize = 32; + u32 fontspace = 1; + + static v2 fs[2]; + if (fs[0].x == 0) { + fs[0] = (v2){ .rl = MeasureTextEx(ctx->font, txt[0], fontsize, fontspace) }; + fs[1] = (v2){ .rl = MeasureTextEx(ctx->font, txt[1], fontsize, fontspace) }; + } pos.x += 130 * dt * scale.x; pos.y += 120 * dt * scale.y; - if (pos.x > (ws.w - fs.x) || pos.x < 0) { + if (pos.x > (ws.w - fs[txt_idx].x) || pos.x < 0) { txt_idx = !txt_idx; - fs = (v2){ .rl = MeasureTextEx(font, txt[txt_idx], 60, 6) }; - CLAMP(pos.x, 0, ws.w - fs.x); + CLAMP(pos.x, 0, ws.w - fs[txt_idx].x); scale.x *= -1.0; } - if (pos.y > (ws.h - fs.y) || pos.y < 0) { + if (pos.y > (ws.h - fs[txt_idx].y) || pos.y < 0) { txt_idx = !txt_idx; - fs = (v2){ .rl = MeasureTextEx(font, txt[txt_idx], 60, 6) }; - CLAMP(pos.y, 0, ws.h - fs.y); + CLAMP(pos.y, 0, ws.h - fs[txt_idx].y); scale.y *= -1.0; } @@ -120,8 +131,8 @@ do_beamformer(BeamformerCtx *ctx, Arena arena, s8 rf_data) DrawTexture(ctx->fsctx.output, 0, 0, WHITE); EndShaderMode(); - DrawTextEx(font, txt[txt_idx], pos.rl, 60, 6, BLACK); - draw_debug_overlay(ctx, arena, font); + DrawTextEx(ctx->font, txt[txt_idx], pos.rl, fontsize, fontspace, BLACK); + draw_debug_overlay(ctx, arena); EndDrawing(); diff --git a/main.c b/main.c @@ -244,6 +244,8 @@ main(void) SetConfigFlags(FLAG_VSYNC_HINT); InitWindow(ctx.window_size.w, ctx.window_size.h, "OGL Beamformer"); + ctx.font = GetFontDefault(); + size out_data_size = ctx.out_data_dim.w * ctx.out_data_dim.h * ctx.out_data_dim.d * sizeof(f32); ctx.out_data_ssbo = rlLoadShaderBuffer(out_data_size, NULL, GL_DYNAMIC_COPY); init_compute_shader_ctx(&ctx.csctx, temp_memory, (uv3){.w = 4093, .h = 128, .d = 1}); diff --git a/util.h b/util.h @@ -94,6 +94,8 @@ typedef struct { uv2 window_size; u32 flags; + Font font; + Color bg, fg; u32 out_data_ssbo;