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
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
#endif // CHARACTERS_H

41
game.c
View file

@ -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
}