load in font

This commit is contained in:
Srayan Jana
2025-09-23 21:34:45 -07:00
parent 9b58e5e1b4
commit c48b9f5b37
4 changed files with 25 additions and 0 deletions
+3
View File
@@ -56,6 +56,9 @@ opaque getKeyState : UInt32 → IO Bool
@[extern "sdl_load_texture"]
opaque loadTexture : String → IO UInt32
@[extern "sdl_load_font"]
opaque loadFont : String → UInt32 → IO Bool
@[extern "sdl_render_texture_column"]
opaque renderTextureColumn : Int32 → Int32 → Int32 → Int32 → Int32 → Int32 → IO Int32
+10
View File
@@ -72,6 +72,16 @@ partial def run : IO Unit := do
SDL.quit
return
unless (← SDL.ttfInit) do
IO.println "Failed to initialize SDL_ttf"
SDL.quit
return
unless (← SDL.loadFont "assets/Inter-VariableFont.ttf" 24) do
IO.println "Failed to load font"
SDL.quit
return
let initialState : EngineState := {
deltaTime := 0.0, lastTime := 0, running := true
}
Binary file not shown.
+12
View File
@@ -7,6 +7,7 @@
static SDL_Window* g_window = NULL;
static SDL_Renderer* g_renderer = NULL;
static SDL_Texture* g_texture = NULL;
static TTF_Font* font = NULL;
lean_obj_res sdl_init(uint32_t flags, lean_obj_arg w) {
int32_t result = SDL_Init(flags);
@@ -126,6 +127,17 @@ lean_obj_res sdl_load_texture(lean_obj_arg filename, lean_obj_arg w) {
return lean_io_result_mk_ok(lean_box(1));
}
lean_obj_res sdl_load_font(lean_obj_arg fontname, uint32_t font_size, lean_obj_arg w) {
const char* fontname_str = lean_string_cstr(fontname);
font = TTF_OpenFont(fontname_str, font_size);
if (!font) {
SDL_Log("C: Failed to load font: %s\n", SDL_GetError());
return lean_io_result_mk_ok(lean_box(0));
}
return lean_io_result_mk_ok(lean_box(1));
}
lean_obj_res sdl_render_texture_column(uint32_t dst_x, uint32_t dst_y, uint32_t dst_height, uint32_t src_x, uint32_t src_y_start, uint32_t src_y_end, lean_obj_arg w) {
if (!g_renderer || !g_texture) return lean_io_result_mk_ok(lean_box_uint32(-1));