The Lyceum Allotments |John Sharp's blog

One final component of a game that I will cover in this tutorial is text. Having a look at the available Emscripten ports (emcc --show-ports) will reveal a library called SDL2_ttf is at your disposal. This is a library that enables you render true type fonts into an SDL_Surface, that can then be rendered in a similar fashion to what we’ve done previously. --show-ports tells us that the command line argument we need to pass to emcc is -s USE_SDL_TTF=2 so all we need to do is add that to our command line, giving us… emcc write_owl.c -O2 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' \ -s USE_SDL2_TTF=2 --preload-file assets -o write_owl.html in our code we need to remember to include the SDL_TTF header file: #include <SDL/SDL_ttf.h> and then we can use the SDL_TTF functions to load a true type font (that we have uploaded to our virtual filesystem, like our image, by placing in a preloaded directory) using: TTF_Font *TTF_OpenFont(const char * file_path, int ptsize) where file_path is the path to the true type font in the virtual filesystem, and ptsize is the size of the font.

posted by John Sharp on Jun 19, 2016

We’re so close to being able to make the perfect game you can almost taste it, there’s just a few things in our way – all that ‘powered by Emscripten’ gumpf that associates itself with or masterwork every time we get Emscripten to generate some HTML for us. That console might come in very useful when we were needing to debug things, but now we’re convinced that our code is completely, absolutely, bug free and we don’t need those crutches any more!

posted by John Sharp on Jun 19, 2016

At long last we’ve reached a position where we can make a 2D game that is something like fully functional. As an illustration I’ve made a simple version of Snake, which can act as a guide for any projects that you’d like to do. It doesn’t really cover anything conceptually new that we haven’t covered before, there’s just more of it, with multiple source files to be compiled. One problem that will be encountered if you just try and compile it using the previous command is that when you try and run the program you’ll be told that you’ve run out of memory.

posted by John Sharp on Jun 19, 2016