From bfe6d485271aa3f28d54b71faa0fa3a16c22a606 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 1 Oct 2023 15:38:15 +0100 Subject: [PATCH] Fix text rendering with bitmap fonts --- src/BitmapFont.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/BitmapFont.c b/src/BitmapFont.c index 54ffdf1..778caa2 100644 --- a/src/BitmapFont.c +++ b/src/BitmapFont.c @@ -93,18 +93,22 @@ void render_bitmap_font_text(AssetManager *am, Renderer *renderer, SDL_Texture *texture = get_texture(am, font->font_atlas); u64 char_index = 0; + RenderRect src = {0}; + + f64 ratio = (f64)font_size / font->tile_height; + u64 width = font->tile_width * ratio; RenderRect dst = { .y = dst_rect.y, - .width = font->tile_width, - .height = font->tile_height, + .width = (f64)width, + .height = font_size, }; for (u64 i = 0; i < length; ++i) { char_index = (u64)(text[i]) - start_index; src = get_character_sprite(font, char_index); - dst.x = i * font->tile_width + dst_rect.x; + dst.x = i * width + dst_rect.x; set_texture_color_modulation(texture, text_color);