SDL TTF 3 Issue
- Posted by Icy_Viking 2 weeks ago
- 584 views
Hi all,
SDL recently released SDL_TTF 3 for SDL 3. However I am having some trouble getting a basic example up and running.
https://github.com/gAndy50/EuSDL3/blob/main/include/SDL_ttf.e - SDL_TTF 3 wrapper
https://wiki.libsdl.org/SDL3_ttf/QuickReference
https://github.com/libsdl-org/SDL_ttf/blob/main/docs/hello.c
This is what I'm trying to convert into Eu code, the program runs fine, but no text is displayed on the screen.
Maybe I'm overlooking something or missing some steps that might be required to display text on the screen?
include std/ffi.e include sdl.e include sdl_ttf.e atom width = 800 atom height = 600 atom flags = NULL if SDL_Init(SDL_INIT_VIDEO+SDL_INIT_EVENTS) = -1 then puts(1,"Failed to init SDL!\n") abort(0) end if sequence title = "Font Example" atom win = SDL_CreateWindow(title,width,height,flags) atom render = SDL_CreateRenderer(win,NULL) atom running = 1 atom event = 0 atom event_type = 0 event = allocate_struct(SDL_Event) sequence color = {255,255,255,SDL_ALPHA_OPAQUE} --SDL_Color if TTF_Init() = -1 then puts(1,"Failed to init TTF!\n") abort(0) end if atom font = TTF_OpenFont("arial.ttf",20) if font = -1 then puts(1,"Failed to open font!\n") abort(0) end if atom text = TTF_RenderText_Blended(font,"Hello World",0,color) atom texture = SDL_CreateTextureFromSurface(render,text) atom w = 0 atom h = 0 atom scale = 4.0 atom text_rect = allocate_struct(SDL_FRect,{w/scale,h/scale,w,h}) while running = 1 do SDL_GetRenderOutputSize(render,w,h) SDL_SetRenderScale(render,scale,scale) SDL_GetTextureSize(texture,w,h) while SDL_PollEvent(event) != 0 do event_type = peek_type(event,C_UINT32) if event_type = SDL_EVENT_QUIT then running = 0 end if end while SDL_RenderClear(render) SDL_RenderTexture(render,texture,NULL,text_rect) SDL_RenderPresent(render) end while SDL_DestroyTexture(texture) SDL_DestroyRenderer(render) SDL_DestroyWindow(win) SDL_Quit()