Mastodon Politics, Power, and Science: Adding font display to the SDL graphics.

Monday, April 23, 2012

Adding font display to the SDL graphics.

[[caption id="attachment_282" align="alignnone" width="300" caption="SDL Font Demo"][/caption]



fontdemo.c

I had to install the SDL_ttf dev library to compile this one.

The command line to compile this is:

gcc `sdl-config --cflags --libs` -lSDL_ttf fontdemo.c


Notice the additional

-lSDL_ttf


that was added.

The original example code is here.

The arial ttf library is at that link. It has to be renamed to all lowercase to work.

I added a check to see of the font was loaded, the program crashes if font is not found. I made the font background transparent so the font would overlay onto the graphic. I added the graphic.

Updated this to use a different method of creating the text.

Everything the same as above, here is the new code:

fontdemo2.c

No comments:

Post a Comment

How Science Makes Simple Ideas Illegible So They Will Read as "Real Science"

 J. Rogers, SE Ohio The Gatekeeping Reflex Einstein said it out loud Einstein criticized his own field in public, and he named the exact ...