we can render a glyph?!

This commit is contained in:
2026-03-06 00:45:20 +01:00
parent 64ee43df24
commit 020fbca785

62
main.c
View File

@@ -3,12 +3,62 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <ft2build.h>
#include <stdlib.h>
#include FT_FREETYPE_H
FT_Library library;
FT_Face face;
EditorState editor_state; EditorState editor_state;
Font editor_font; Font editor_font;
void ed_load_font() {} #define ERROR(module, error) \
{ \
printf("ERROR (%s): %s\n", (module), (error)); \
}
int main() { int main() {
FT_Error error = FT_Init_FreeType(&library);
if (error) {
ERROR("freetype", FT_Error_String(error))
exit(EXIT_FAILURE);
}
error = FT_New_Face(library, "/usr/share/fonts/noto/NotoSans-Regular.ttf",
0, &face);
if (error) {
ERROR("freetype", FT_Error_String(error))
exit(EXIT_FAILURE);
}
error = FT_Set_Char_Size(face, 0, 16 * 18, 800, 600);
if (error) {
ERROR("freetype", FT_Error_String(error))
exit(EXIT_FAILURE);
}
FT_UInt idx = FT_Get_Char_Index(face, '&');
printf("Index: %d\n", idx);
error = FT_Load_Glyph(face, 32, FT_LOAD_DEFAULT);
if (error) {
ERROR("freetype", FT_Error_String(error))
exit(EXIT_FAILURE);
}
error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
if (error) {
ERROR("freetype", FT_Error_String(error))
exit(EXIT_FAILURE);
}
FT_GlyphSlot slot = face->glyph;
sds init_text = sdsnew("Das ist nur ein Test String🙂!"); sds init_text = sdsnew("Das ist nur ein Test String🙂!");
editor_state = init_editor_state(init_text); editor_state = init_editor_state(init_text);
@@ -16,6 +66,14 @@ int main() {
InitWindow(800, 600, "editor"); InitWindow(800, 600, "editor");
Image img = (Image){.data = slot->bitmap.buffer,
.width = slot->bitmap.width,
.height = slot->bitmap.rows,
.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE,
.mipmaps = 1};
Texture2D tex = LoadTextureFromImage(img);
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
@@ -23,6 +81,8 @@ int main() {
DrawText(editor_state.text, 8, 8, 18, RAYWHITE); DrawText(editor_state.text, 8, 8, 18, RAYWHITE);
DrawRectangle(8 * editor_state.cursor_pos + 8, 8, 2, 18, GREEN); DrawRectangle(8 * editor_state.cursor_pos + 8, 8, 2, 18, GREEN);
DrawTexture(tex, 40, 40, WHITE);
EndDrawing(); EndDrawing();
} }