Text Rendering with TTF_RenderText_Solid, TTF_OpenFont etc

388 views
Skip to first unread message

Thomas Arnbjerg

unread,
Apr 18, 2016, 4:14:12 PM4/18/16
to emscripten-discuss
Hi all,

I'm trying to render text using the TTF functions.

Basically I call the following functions in the sequence shown:

SDL_Init // Initialize SDL
TTF_Init // Initialize TTF
SDL_CreateWindow // Create a window
SDL_CreateRenderer // Create a renderer for the window
TTF_OpenFont // Open a font (I tried different names "arial" or "sans-serif")
TTF_RenderText_Solid  // Create a surface witht the text "Hello"
SDL_CreateTextureFromSurface  // Create a texture based on the surface based on the windows renderer
SDL_RenderCopy  // Copy the texture to the window renderer
SDL_RenderPresent  // Update the window.

All functions succeed - but no text is shown. Any ideas - or can you point me to a good example on how to use TTF with windows and renderers?

Thx

Thomas

juj j

unread,
Apr 24, 2016, 4:46:07 AM4/24/16
to emscripte...@googlegroups.com
There are two different implementations for SDL_TTF via SDL1 (in src/library_sdl.js), and SDL2 (via the compiled SDL repository). Not sure what would be the issue here, but looks like there is one relevant looking bug report about this here: https://github.com/kripken/emscripten/issues/3703

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Arnbjerg

unread,
Apr 25, 2016, 9:17:39 AM4/25/16
to emscripten-discuss
Thank's for the help
.
I don't get any errors though.

Just to have all experiments collected in one place I also tried the following without success:

1) Insert a delay between TTF_OpenFont and TTF_RenderText_Solid to allow the browser to load the font (hint another posting somewhere else)
2) Use a font name referenced in the HTML file to ensure that the browser has loaded the font (another hint).
Message has been deleted

Thomas Arnbjerg

unread,
May 2, 2016, 6:59:29 PM5/2/16
to emscripten-discuss
Update:

I did not call emcc with the arguments '-s USE_SDL_TTF=2 -s USE_FREETYPE=1'.

Adding these now causes TTF_OpenFont to fail.

Thomas Arnbjerg

unread,
May 6, 2016, 5:08:50 PM5/6/16
to emscripten-discuss
Problem solved: TTF_OpenFont failed because no font was embedded with '-embed-file'
Reply all
Reply to author
Forward
0 new messages