fix: draw text

This commit is contained in:
orangerot 2025-10-14 23:22:56 +02:00
parent 88135bb849
commit 510eae4276
2 changed files with 23 additions and 24 deletions

View file

@ -4,8 +4,8 @@
#define CHARACTERS_H #define CHARACTERS_H
uint32_t characters[96] = uint32_t characters[96] = {
{0b000000000000000000000000000000, // SPACE 0b000000000000000000000000000000, // SPACE
0b100001000010000000001000000000, // ! 0b100001000010000000001000000000, // !
0b101001010000000000000000000000, // " 0b101001010000000000000000000000, // "
0b010101111101010111110101000000, // # 0b010101111101010111110101000000, // #
@ -103,4 +103,4 @@ uint32_t characters[96] =
0b000000000000000000000000000000 // DEL 0b000000000000000000000000000000 // DEL
}; };
#endif // CHARACTERS_H #endif // CHARACTERS_H

41
game.c
View file

@ -121,35 +121,34 @@ draw(
void void
draw_character( draw_character(
struct image canvas, struct image canvas,
char character, char *character,
size_t xpos, size_t ypos size_t xpos, size_t ypos
) { ) {
const int character_width = 5; struct image texture = {
const int character_height = 6; .width = 5,
struct image texture; .height = 6,
texture.width = character_height; .bufsize = 5 * 6,
texture.height = character_width; .buf = (uint32_t[30]) {0}
texture.buf = (uint32_t[30]) {0}; };
const uint32_t bitmask = characters[character - ' '];
for (size_t i = 0; character[i]; i++) {
for (size_t i = 0; i < character_width; i++) { const uint32_t bitmask = characters[character[i] - ' '];
for (size_t j = 0; j < character_height; j++) { texture.buf = (uint32_t[30]) {0};
if (bitmask >> ((character_height - j - 1) * character_width + (character_width - i + 1)) & 1) {
// (0b101101 >> ((height - y - 1) * width + (width - x + 1))) & 1 for (size_t y = 0; y < texture.height; y++) {
texture.color[j*character_width + i] = (struct color){255, 255, 255, 0}; 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 //void
//draw_text( //draw_text(
// //
//) //)
void render(struct image canvas) { void render(struct image canvas) {
@ -207,7 +206,7 @@ void render(struct image canvas) {
} }
// character // character
draw_character(canvas, 'D', 50, 20); // debugging draw_character(canvas, "Hallo Welt", 50, 20); // debugging
} }