From 510eae42763ae59def576bcc6e72b44083ec1d41 Mon Sep 17 00:00:00 2001 From: orangerot Date: Tue, 14 Oct 2025 23:22:56 +0200 Subject: [PATCH] fix: draw text --- characters.h | 6 +++--- game.c | 41 ++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/characters.h b/characters.h index 3450875..679f394 100644 --- a/characters.h +++ b/characters.h @@ -4,8 +4,8 @@ #define CHARACTERS_H -uint32_t characters[96] = - {0b000000000000000000000000000000, // SPACE +uint32_t characters[96] = { + 0b000000000000000000000000000000, // SPACE 0b100001000010000000001000000000, // ! 0b101001010000000000000000000000, // " 0b010101111101010111110101000000, // # @@ -103,4 +103,4 @@ uint32_t characters[96] = 0b000000000000000000000000000000 // DEL }; - #endif // CHARACTERS_H \ No newline at end of file + #endif // CHARACTERS_H diff --git a/game.c b/game.c index c98cc78..a34aafc 100644 --- a/game.c +++ b/game.c @@ -121,35 +121,34 @@ draw( void draw_character( struct image canvas, - char character, + char *character, size_t xpos, size_t ypos ) { - const int character_width = 5; - const int character_height = 6; - struct image texture; - texture.width = character_height; - texture.height = character_width; - texture.buf = (uint32_t[30]) {0}; - const uint32_t bitmask = characters[character - ' ']; - - for (size_t i = 0; i < character_width; i++) { - for (size_t j = 0; j < character_height; j++) { - if (bitmask >> ((character_height - j - 1) * character_width + (character_width - i + 1)) & 1) { - // (0b101101 >> ((height - y - 1) * width + (width - x + 1))) & 1 - texture.color[j*character_width + i] = (struct color){255, 255, 255, 0}; + struct image texture = { + .width = 5, + .height = 6, + .bufsize = 5 * 6, + .buf = (uint32_t[30]) {0} + }; + + for (size_t i = 0; character[i]; i++) { + const uint32_t bitmask = characters[character[i] - ' ']; + texture.buf = (uint32_t[30]) {0}; + + for (size_t y = 0; y < texture.height; y++) { + for (size_t x = 0; x < texture.width; x++) { + if ((bitmask >> ((texture.height - y - 1) * texture.width + (texture.width - x - 1))) & 1) { + texture.buf[y * texture.width + x] = -1; + } } - //else { - // texture.color[j*character_width + i] = (struct color){0, 0, 0, 255}; - //}; - } + draw(canvas, texture, xpos + i * texture.width, ypos); } - draw(canvas, texture, xpos, ypos); } //void //draw_text( -// +// //) void render(struct image canvas) { @@ -207,7 +206,7 @@ void render(struct image canvas) { } // character - draw_character(canvas, 'D', 50, 20); // debugging + draw_character(canvas, "Hallo Welt", 50, 20); // debugging }