* More documentation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
diff --git a/docs/ftgl.dox b/docs/ftgl.dox
index b3f3dac..fe57107 100644
--- a/docs/ftgl.dox
+++ b/docs/ftgl.dox
@@ -22,6 +22,13 @@
Word you don't need an intermediate pre-processing step to use high quality
scalable fonts.
+ \section starting Starting to use FTGL
+
+ Only one header is required to use %FTGL:
+
+\code
+#include <FTGL/ftgl.h>
+\endcode
\section type Choosing a font type
@@ -61,34 +68,47 @@
\image html texturefont.png
\image latex texturefont.eps "" width=0.7\textwidth
- \section creating Creating a font
+ \section creating Create font objects
+
+ Creating a font and displaying some text is really straightforward, be it
+ in C or in C++.
+
+ \subsection c in C
\code
-FTGLPixmapFont font;
+/* Create a pixmap font from a TrueType file. */
+FTGLfont *font = ftglCreatePixmapFont("/home/user/Arial.ttf");
-font.Open("Fonts:Arial");
-font.FaceSize(72);
+/* If something went wrong, bail out. */
+if(!font)
+ return -1;
-font.Render("Hello World!");
+/* Set the font size and render a small text. */
+ftglSetFontFaceSize(font, 72, 72);
+ftglRenderFont(font, "Hello World!", FTGL_RENDER_ALL);
+
+/* Destroy the font object. */
+ftglDestroyFont(font);
\endcode
- A side effect of this is you can specify a sub set of glyphs to be pre-loaded.
- This will let you use larger higher quality glyphs without consuming huge
- amounts of ram as you would if you loaded the entire font. For example if your
- application only needs numbers, eg for scores, you can use the following code
- to preload them.
+ \subsection cxx in C++
\code
-// Open the font with pre-cache set to false
-font.Open("Fonts:Arial", false);
+// Create a pixmap font from a TrueType file.
+FTGLPixmapFont font("/home/user/Arial.ttf");
-// Set the size
-font.FaceSize(72);
+// If something went wrong, bail out.
+if(font.Error())
+ return -1;
-// Cause the font to preload the number chars without rendering them.
-font.Advance("0123456789");
+// Set the font size and render a small text.
+font.FaceSize(72);
+font.Render("Hello World!");
\endcode
+ The first 128 glyphs of the font (generally corresponding to the ASCII set)
+ are preloaded. This means that usual text is rendered fast enough, but no
+ memory is wasted loading glyphs that will not be used.
\section commands More font commands
@@ -121,8 +141,9 @@ font.Advance("0123456789");
Valid encodings as of FreeType 2.0.4 are:
- ft_encoding_none
- - ft_encoding_symbol
- ft_encoding_unicode
+ - ft_encoding_symbol
+ - ft_encoding_latin_1
- ft_encoding_latin_2
- ft_encoding_sjis
- ft_encoding_gb2312
@@ -143,6 +164,35 @@ font.CharMap(ft_encoding_apple_roman);
This will return an error if the requested encoding can't be found in the
font.
+ If your application uses Latin-1 characters, you can preload this character
+ set using the following code:
+
+ \code
+// Create a pixmap font from a TrueType file.
+FTGLPixmapFont font("/home/user/Arial.ttf");
+
+// If something went wrong, bail out.
+if(font.Error())
+ return -1;
+
+// Set the face size and the character map. If something went wrong, bail out.
+font.FaceSize(72);
+if(!font.CharMap(ft_encoding_latin_1))
+ return -1;
+
+// Create a string containing all characters between 128 and 255
+// and preload the Latin-1 chars without rendering them.
+char buf[129];
+for(int i = 128; i < 256; i++)
+{
+ buf[i] = (char)(unsigned char)i;
+}
+buf[128] = '\0';
+
+font.Advance(buf);
+}
+ \endcode
+
\section faq FAQ