fix: draw text
This commit is contained in:
parent
88135bb849
commit
510eae4276
|
@ -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, // #
|
||||||
|
|
37
game.c
37
game.c
|
@ -121,30 +121,29 @@ 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; i < character_width; i++) {
|
for (size_t i = 0; character[i]; i++) {
|
||||||
for (size_t j = 0; j < character_height; j++) {
|
const uint32_t bitmask = characters[character[i] - ' '];
|
||||||
if (bitmask >> ((character_height - j - 1) * character_width + (character_width - i + 1)) & 1) {
|
texture.buf = (uint32_t[30]) {0};
|
||||||
// (0b101101 >> ((height - y - 1) * width + (width - x + 1))) & 1
|
|
||||||
texture.color[j*character_width + i] = (struct color){255, 255, 255, 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
|
//void
|
||||||
|
@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue