Sunday, December 9, 2012

Font Rendering with Freetype and Libpng (Part 2)

Hi there,

this is part two of rendering a font with freetype into a PNG image. In this second part I will show how to cross-compile the program we created in the first part for Windows x64.
I'm going to use the mingw-w64 project which makes it very easy. Just install the mingw-w64 package.
$ sudo aptitude install mingw-w64
After successful installation you can use the mingw-w64 toolchain:
$ x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-gcc (GCC) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Now we just have to use this to compile freetype, zlib and libpng. Unfortunately the average build system is not really prepared for cross-compilation and even if it is it's not necessarily built with mingw-w64 in mind. Therefore it is usually necessary to fiddle around with various parameters to configure and make.

Cross-Compiling the Libraries

$ cd freetype-2.4.10
$ make clean
$ ./configure --disable-shared CC=x86_64-w64-mingw32-gcc RANLIB=x86_64-w64-mingw32-ranlib AR=x86_64-w64-mingw32-ar --host=x86_64
$ make
$ cp objs/.libs/libfreetype.a ../font-render/libs/win64/

$ cd ../zlib-1.2.7
$ make clean
$ ./configure --static
$ make CC=x86_64-w64-mingw32-gcc RANLIB=x86_64-w64-mingw32-ranlib AR=x86_64-w64-mingw32-ar
$ cp libz.a ../font-render/libs/win64/

$ cd ../libpng-1.5.13
$ make clean
$ ./configure --disable-shared CC=x86_64-w64-mingw32-gcc RANLIB=x86_64-w64-mingw32-ranlib AR=x86_64-w64-mingw32-ar --host=x86_64 CFLAGS=-L../zlib-1.2.7
$ make CFLAGS='-L../zlib-1.2.7 -I../zlib-1.2.7'
$ cp .libs/libpng15.a ../font-render/libs/win64/
Now you should be able to compile the program for Windows x64:
$ cd ../font-render
$ x86_64-w64-mingw32-gcc -Wall -pedantic -std=c99 -Iinclude -Llibs/win64 render-text.c -o render-text.exe -lfreetype -lpng15 -lz -lm
And that's it.

To keep it short and sweet, I will postpone the rendering of multiple characters to a third part. Don't worry, I will post it soon.

As always, if you have any comments, critique, suggestions or just want to tell me how much I suck please use the comment form below. I would appreciate your feedback.

1 comment:

  1. When are you planning to post third part of rendering of multiple characters??

    ReplyDelete