%include "inc/generic.inc" %include "inc/sdl2.inc" %include "include/rge.inc" BITS 64 DEFAULT REL global RG_Subsys_TTF_init global RG_Load_Font global RG_Write_Text extern RG_Abort section code_section ;; Initializes the TTF subsystem RG_Subsys_TTF_init: funcstart saveregs rbx stksetup exmcall TTF_Init mov rbx, rax test rax, rax jz .ok ; error ; TTF_GetError is an alias for SDL_GetError exmcall SDL_GetError lea areg1, [sdl_err_fmt] mov areg2, rax exmcall printf mov rax,rbx .ok: lea areg1, [fmt] lea areg2, [initstr] exmcall printf mov rax,rbx funcend ;; Load a font ;; @param areg1 = font file ;; @param areg2 = point size RG_Load_Font: funcstart var 8, %$font stksetup mov [%$font], areg1 mov rax, [Font] test rax,rax jz .emptyptr exmcall RG_DebugPrint, "Font already loaded, closing" mov areg1, [Font] exmcall TTF_CloseFont .emptyptr: mov areg1, [%$font] test areg2, areg2 exmcall TTF_OpenFont test rax,rax ifc z exmcall RG_DebugPrint, "Failed to load font" exmcall RG_DebugPrint, [%$$font] call RG_Abort endif mov [Font], rax funcend ;; Render text onto a new texture and return a pointer to it ;; The intermediate SDL_Surface* gets freed automatically ;; Font must be loaded prior to calling this function, otherwise ;; the engine will abort and close ;; @param areg1 - renderer ;; @param areg2 - text ptr ;; @param areg3 - color ;; @param areg4 - wrap length ;; @return RAX - pointer to texture with text RG_Write_Text: funcstart var 8, %$surf, %$tex, %$rend stksetup mov [%$rend],areg1 mov areg1,[Font] test areg1, areg1 ifc z exmcall RG_DebugPrint, "Font not loaded! Bailing out!" call RG_Abort endif exmcall TTF_RenderText_Solid_Wrapped ; rax = SDL_Surface * mov [%$surf], rax mov areg1, [%$rend] mov areg2, rax exmcall SDL_CreateTextureFromSurface mov [%$tex], rax mov areg1, [%$surf] exmcall SDL_FreeSurface mov rax,[%$tex] funcend section .bss ;; Address of pointer for the loaded font Font: resq 1 section ro_section sdl_err_fmt: db "SDL2 [SDL_ttf] Error: %s",10,0 fmt: db "RGE [TTF]: %s",10,0 initstr: db "TTF Subsystem initialized",0 .