~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to extern/bFTGL/docs/FTGL.html

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
2
<head>
 
3
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 
4
    <title>FTGL User Guide</title>
 
5
</head>
 
6
<body>
 
7
 
 
8
<TABLE BORDER="0" WIDTH="70%" CELLSPACING="0" CELLPADDING="0" ALIGN="center">
 
9
        <TR>
 
10
                <TD>
 
11
 
 
12
<h1>FTGL User Guide
 
13
</h1>
 
14
<h2>(work in progress)
 
15
</h2>
 
16
<P ALIGN="center">
 
17
<IMG SRC="images/ftgldemo.jpg" ALT="FTGL Demo screen shot" WIDTH="480" HEIGHT="383" BORDER="0">
 
18
</P>
 
19
 
 
20
<H2>Contents</H2>
 
21
<UL>
 
22
        <LI><H3><a href="#INT">Introduction</a></H3></LI>
 
23
        <LI><H3><a href="#CFT">Choosing a font type</a></H3></LI>
 
24
        <LI><H3><a href="#CAT">Creating a font</a></H3></LI>
 
25
        <LI><H3><a href="#MFC">More font commands</a></H3></LI>
 
26
        <LI><H3><a href="#FAQ">FAQ</a></H3></LI>
 
27
        <LI><H3><a href="#GLS">Glossary</a></H3></LI>
 
28
</UL>
 
29
<HR ALIGN="center" SIZE="2" WIDTH="80%">
 
30
<A NAME="INT">
 
31
<h2>Introduction
 
32
</h2>
 
33
<P>
 
34
OpenGL doesn't provide direct font support, so the application must use any of OpenGL's other features for font rendering, such as drawing bitmaps or pixmaps, creating texture maps containing an entire character set, drawing character outlines, or creating 3D geometry for each character.
 
35
</P>
 
36
 
 
37
 
 
38
<P>http://www.opengl.org/developers/faqs/technical/fonts.htm</P>
 
39
<P>http://www.opengl.org/developers/code/features/fontsurvey/index.html</P>
 
40
<P>
 
41
?????One thing all of these systems have in comman is they require a pre-processing stage to take the native fonts and convert them into proprietry format.
 
42
</P>
 
43
 
 
44
<P>
 
45
FTGL was borne out of the need to treat fonts in OpenGL applications just like any other application. For example when using Adobe Photoshop or Microsoft Word you don't need an intermediate pre-processing step to use high quality scalable fonts. 
 
46
</P>
 
47
 
 
48
<HR ALIGN="center" SIZE="2" WIDTH="80%">
 
49
<A NAME="CFT">
 
50
<H2>Choosing a font type</H2>
 
51
<P>
 
52
FTGL supports 6 font output types in 3 groups, raster fonts, vector fonts and texure fonts which are a mixture of both. Each font type has it's advantages and disadvantages
 
53
</P>
 
54
The two raster types are
 
55
<UL>
 
56
        <LI>Bitmapped</LI>
 
57
        <LI>Antialiased pixmapped</LI>
 
58
</UL>
 
59
 
 
60
 
 
61
 
 
62
The vector types are
 
63
<UL>
 
64
        <LI>Outline</LI>
 
65
        <LI>Polygonal</LI>
 
66
        <LI>Extruded polygon</LI>
 
67
</UL>
 
68
 
 
69
 
 
70
 
 
71
 
 
72
<UL>
 
73
        <LI>Texture mapped</LI>
 
74
</UL>
 
75
<P>
 
76
This is probably the most versatile type. It is fast, antialised and can be transformed just like any openGL primitive.
 
77
</P>
 
78
 
 
79
<HR ALIGN="center" SIZE="2" WIDTH="80%">
 
80
 
 
81
<A NAME="CAF">
 
82
<H2>Creating a font
 
83
</H2>
 
84
<font color="blue"><PRE>
 
85
    FTGLPixmapFont font;
 
86
    
 
87
    font.Open( "Fonts:Arial");
 
88
    font.FaceSize( 72);
 
89
    
 
90
    font.render( "Hello World!");
 
91
 
 
92
    FTFont::Open( string, cache);
 
93
    const char* string;    
 
94
    bool cache;            
 
95
</PRE></font>
 
96
<P>
 
97
<font color="blue"><PRE>
 
98
                bool Open( fontname, preCache = true);
 
99
        const char* fontname:   
 
100
        bool preCache:          
 
101
 
 
102
</PRE></font>
 
103
 
 
104
 
 
105
<P>
 
106
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.
 
107
</P>
 
108
 
 
109
<font color="blue"><PRE>
 
110
    // Open the font with pre-cache set to false
 
111
    font.Open( "Fonts:Arial", false);
 
112
    
 
113
    // Set the size
 
114
    font.FaceSize( 72);
 
115
    
 
116
    // Cause the font to preload the number chars without rendering them.
 
117
    font.Advance( "0123456789");
 
118
</PRE></font>
 
119
 
 
120
 
 
121
 
 
122
<HR ALIGN="center" SIZE="2" WIDTH="80%">
 
123
 
 
124
<A NAME="MFC">
 
125
<H2>More font commands</H2>
 
126
<H3>Font Metrics</H3>
 
127
<P ALIGN="center">
 
128
<IMG SRC="images/metrics.png" ALT="glyph metrics" WIDTH="388" HEIGHT="253" BORDER="0">
 
129
</P>
 
130
 
 
131
<P>
 
132
If you ask a font to render at 0.0, 0.0 the bottom left most pixel or polygon may not be aligned to 0.0, 0.0.
 
133
</P>
 
134
 
 
135
<font color="blue"><PRE>
 
136
        int    FTFont::Ascender() const;
 
137
        int    FTFont::Descender() const;
 
138
 
 
139
        float FTFont::Advance( string);
 
140
</PRE></font>
 
141
 
 
142
 
 
143
<P>
 
144
With these three functions an approximate bounding box can be calculated. For an exact bounding box use the FTFont::BBox function.
 
145
</P>
 
146
 
 
147
<font color="blue"><PRE>
 
148
        void FTFont::BBox( string, llx, lly, llz, urx, ury, urz);
 
149
        const char* string:    String of text to be tested
 
150
        float& llx:            The bottom left near most ?? in the x axis
 
151
        float& lly:            The bottom left near most ?? in the y axis
 
152
        float& llz:            The bottom left near most ?? in the z axis
 
153
        float& urx:            The top right far most ?? in the x axis
 
154
        float& ury:            The top right far most ?? in the y axis
 
155
        float& urz:            The top right far most ?? in the z axis
 
156
</PRE></font>
 
157
 
 
158
<P>
 
159
This function returns the extent of the volume containing 'string'. 0.0 on the y axis will be aligned with the font baseline.
 
160
</P>
 
161
 
 
162
<H3>Specifying a character map encoding.
 
163
</H3>
 
164
From the freetype docs...<br>
 
165
"By default, when a new face object is created, (freetype) lists all the charmaps contained in the font face and selects the one that supports Unicode character codes if it finds one. Otherwise, it tries to find support for Latin-1, then ASCII."
 
166
<BR>
 
167
It then gives up. In this case FTGL will set the charmap to the first it finds in the fonts charmap list.
 
168
 
 
169
You can expilcitly set the char encoding with Charmap:
 
170
<font color="blue"><PRE>
 
171
    bool FTFont::CharMap( encoding);
 
172
    FT_Encoding encoding;    Freetype code
 
173
</PRE></font>
 
174
    
 
175
Valid encodings as at Freetype 2.0.4
 
176
<font color="blue"><PRE>
 
177
    ft_encoding_none
 
178
    ft_encoding_symbol
 
179
    ft_encoding_unicode
 
180
    ft_encoding_latin_2
 
181
    ft_encoding_sjis
 
182
    ft_encoding_gb2312
 
183
    ft_encoding_big5
 
184
    ft_encoding_wansung
 
185
    ft_encoding_johab
 
186
    ft_encoding_adobe_standard
 
187
    ft_encoding_adobe_expert
 
188
    ft_encoding_adobe_custom
 
189
    ft_encoding_apple_roman
 
190
</PRE></font>
 
191
 
 
192
for example...
 
193
<font color="blue"><PRE>
 
194
font.CharMap( ft_encoding_apple_roman);
 
195
</PRE></font>
 
196
 
 
197
This will return an error if the requested encoding can't be found in the font.
 
198
 
 
199
 
 
200
 
 
201
<HR ALIGN="center" SIZE="2" WIDTH="80%">
 
202
 
 
203
<A NAME="FAQ">
 
204
<H2>FAQ</H2>
 
205
 
 
206
WhenI try to compile FTGL it complains about a missing file from the include:
 
207
 
 
208
#include <ft2build.h>
 
209
 
 
210
FTGL relies on freetype 2 for opening and decoding font files. This include is the main include for freetype. You will need to download Freetype 2 and install it. Then make sure that the FTGL project that you are using points to your freetype installation.
 
211
 
 
212
 
 
213
2) Is it possible to map a font to a "unit" size? My application relies on
 
214
the fonts being a certain "physical" height (in OpenGL coordinate space)
 
215
rather than a point size in display space. Any thoughts/suggestions?
 
216
 
 
217
 
 
218
We can do anything:) It would be easy to allow you to set the size in pixels, though I'm not sure this is what you want. Setting the size to 'opengl units' may be a bit harder. What does 1.0 in opengl space mean and how does that relate to point size? For one person it might mean scaling the font up, for someone else it may mean scaling down. Plus bitmaps and pixmaps have a pixel to pixel relationship that you can't change.
 
219
 
 
220
Here's some guidelines for vector and texture fonts. Take note that I say 'should' a lot:)
 
221
One point in pixel space maps to 1 unit in opengl space, so a glyph that is 18 points high should be 18.0 units high.
 
222
If you set an ortho projection to the window size and draw a glyph it's screen size should be the correct physical size ie a 72 point glyph on a 72dpi screen will be 1 inch high. Also if you set a perspective projection that maps 0.0 in the z axis to screen size you will get the same eg...
 
223
        gluPerspective( 90, window_height / 2 , small_number, large_number);
 
224
So basically it all depends on your projection matrix. Obviously you can use glScale but I understand if you don't want to.
 
225
Couple of extra things to note. The quality of vector glyphs will not change when you change the size. ie a really small polygon glyph up close will look exactly the same as a big one from far away. They both contain the same amount of data. This doesn't apply to texture fonts. Secondly there is a bug in the advance/ kerning code that will cause ugliness at really small point sizes. This is because the advance and kerning use ints so an advance of 0.4 will become zero. If this is going to be a probelm, I can fix this.
 
226
 
 
227
Early on I did a lot of head scratching over the opengl unit to font size thing because when I was first integrating FTGL into my engine the fonts weren't the size I was expecting. I was tempted to build in some scaling but I decided doing nothing was the best approach because you can't please everyone. Plus it's 'correct' as it is.
 
228
 
 
229
 
 
230
 
 
231
<H3>Sample font manager class.</H3>
 
232
 
 
233
 
 
234
<font color="blue"><pre>
 
235
FTGLTextureFont* myFont = FTGLFontManager::Instance().GetFont( "arial.ttf", 72);
 
236
 
 
237
#include    &lt;map&gt;
 
238
#include    &lt;string&gt;
 
239
#include    "FTGLTextureFont.h"
 
240
 
 
241
using namespace std;
 
242
 
 
243
typedef map< string, FTFont*> FontList;
 
244
typedef FontList::const_iterator FontIter;
 
245
 
 
246
class FTGLFontManager
 
247
{
 
248
    public:
 
249
        // NOTE
 
250
        // This is shown here for brevity. The implementation should be in the source
 
251
        // file otherwise your compiler may inline the function resulting in 
 
252
        // multiple instances of FTGLFontManager
 
253
        static FTGLFontManager& Instance()
 
254
        {
 
255
            static FTGLFontManager tm;
 
256
            return tm;
 
257
        }
 
258
        
 
259
        ~FTGLFontManager()
 
260
        {
 
261
            FontIter font;
 
262
            for( font = fonts.begin(); font != fonts.end(); font++)
 
263
            {
 
264
                delete (*font).second;;
 
265
            }
 
266
    
 
267
            fonts.clear();
 
268
        }
 
269
 
 
270
        
 
271
        FTFont* GetFont( const char *filename, int size)
 
272
        {
 
273
            char buf[256];
 
274
            sprintf(buf, "%s%i", filename, size);
 
275
            string fontKey = string(buf);
 
276
            
 
277
            FontIter result = fonts.find( fontKey);
 
278
            if( result != fonts.end())
 
279
            {
 
280
                LOGMSG( "Found font %s in list", filename);
 
281
                return result->second;
 
282
            }
 
283
        
 
284
            FTFont* font = new FTGLTextureFont;
 
285
            
 
286
            string fullname = path + string( filename);
 
287
            
 
288
            if( !font->Open( fullname.c_str()))
 
289
            {
 
290
                LOGERROR( "Font %s failed to open", fullname.c_str());
 
291
                delete font;
 
292
                return NULL;
 
293
            }
 
294
            
 
295
            if( !font->FaceSize( size))
 
296
            {
 
297
                LOGERROR( "Font %s failed to set size %i", filename, size);
 
298
                delete font;
 
299
                return NULL;
 
300
            }
 
301
        
 
302
            fonts[fontKey] = font;
 
303
            
 
304
            return font;
 
305
        
 
306
        }
 
307
    
 
308
        
 
309
    private:
 
310
        // Hide these 'cause this is a singleton.
 
311
        FTGLFontManager(){}
 
312
        FTGLFontManager( const FTGLFontManager&){};
 
313
        FTGLFontManager& operator = ( const FTGLFontManager&){ return *this;};
 
314
        
 
315
        // container for fonts
 
316
        FontList fonts;
 
317
    
 
318
};
 
319
</PRE></font>
 
320
 
 
321
 
 
322
<HR ALIGN="center" SIZE="2" WIDTH="80%">
 
323
 
 
324
<A NAME="GLS">
 
325
<H2>Glossary</H2>
 
326
 
 
327
 
 
328
                </TD>
 
329
        </TR>
 
330
</TABLE>
 
331
</body>
 
332
</html>