Commit 2d7750d7270b9307e95f87ab870e5171ac1d2f65

sammy 2008-04-13T21:39:26

* Merged trunk commits [678] and [711], by henry: + Created a demo that can handle multiple fonts and command line options. + Updated for new compiler.

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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
diff --git a/demo/FTGLMFontDemo.cpp b/demo/FTGLMFontDemo.cpp
new file mode 100644
index 0000000..186630f
--- /dev/null
+++ b/demo/FTGLMFontDemo.cpp
@@ -0,0 +1,615 @@
+#ifdef __APPLE_CC__
+	#include <GLUT/glut.h>
+#else
+	#include <GL/glut.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "tb.h"
+
+#include "FTGLExtrdFont.h"
+#include "FTGLOutlineFont.h"
+#include "FTGLPolygonFont.h"
+#include "FTGLTextureFont.h"
+#include "FTGLPixmapFont.h"
+#include "FTGLBitmapFont.h"
+#include "FTSimpleLayout.h"
+
+// YOU'LL PROBABLY WANT TO CHANGE THESE
+#ifdef __linux__
+    char const *defaultFonts[] = { "/usr/share/fonts/truetype/arial.ttf" };
+    const int NumDefaultFonts = 1;
+#endif
+#ifdef __APPLE_CC__
+	//#define FONT_FILE "/Users/henry/Development/PROJECTS/FTGL/ftglcvs/FTGL/test/arial.ttf"
+    char const *defaultFonts[] = { "/System/Library/Fonts/Helvetica.dfont","/System/Library/Fonts/Geneva.dfont" };
+    const int NumDefaultFonts = 2;
+#endif
+#ifdef WIN32
+    char const *defaultFonts[] = { "C:\\WINNT\\Fonts\\arial.ttf" };
+    const int NumDefaultFonts = 1;
+#endif
+#ifndef FONT_FILE
+	#define FONT_FILE 0
+#endif
+
+/* Set this to 1 to build a Mac os app (ignore the command line args). */
+#ifndef IGNORE_ARGV
+ #define IGNORE_ARGV 0
+#endif /* IGNORE_ARGV */
+
+#define EDITING 1
+#define INTERACTIVE 2
+
+#define FTGL_BITMAP 0
+#define FTGL_PIXMAP 1
+#define FTGL_OUTLINE 2
+#define FTGL_POLYGON 3
+#define FTGL_EXTRUDE 4
+#define FTGL_TEXTURE 5
+const int NumStyles = 6;
+
+char const **fontfiles;
+int current_font = FTGL_EXTRUDE;
+
+GLint w_win = 640, h_win = 480;
+int mode = INTERACTIVE;
+int carat = 0;
+
+FTSimpleLayout simpleLayout;
+FTLayout			*layouts[] = { &simpleLayout, NULL};
+int currentLayout = 0;
+const int NumLayouts = 2;
+
+const float InitialLineLength = 300.0f;
+
+const float OX = -100;
+const float OY = 200;
+
+//wchar_t myString[16] = { 0x6FB3, 0x9580};
+char myString[4096];
+
+int totalFonts;
+static FTFont** fonts;
+static FTGLPixmapFont* infoFont;
+
+void SetCamera(void);
+
+inline int GetStyle() 
+   { return(current_font%NumStyles); }
+inline int GetFace() 
+   { return(current_font/NumStyles); }
+   
+void setUpLighting()
+{
+   // Set up lighting.
+   float light1_ambient[4]  = { 1.0, 1.0, 1.0, 1.0 };
+   float light1_diffuse[4]  = { 1.0, 0.9, 0.9, 1.0 };
+   float light1_specular[4] = { 1.0, 0.7, 0.7, 1.0 };
+   float light1_position[4] = { -1.0, 1.0, 1.0, 0.0 };
+   glLightfv(GL_LIGHT1, GL_AMBIENT,  light1_ambient);
+   glLightfv(GL_LIGHT1, GL_DIFFUSE,  light1_diffuse);
+   glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
+   glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
+   glEnable(GL_LIGHT1);
+
+   float light2_ambient[4]  = { 0.2, 0.2, 0.2, 1.0 };
+   float light2_diffuse[4]  = { 0.9, 0.9, 0.9, 1.0 };
+   float light2_specular[4] = { 0.7, 0.7, 0.7, 1.0 };
+   float light2_position[4] = { 1.0, -1.0, -1.0, 0.0 };
+   glLightfv(GL_LIGHT2, GL_AMBIENT,  light2_ambient);
+   glLightfv(GL_LIGHT2, GL_DIFFUSE,  light2_diffuse);
+   glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);
+   glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
+//   glEnable(GL_LIGHT2);
+
+   float front_emission[4] = { 0.3, 0.2, 0.1, 0.0 };
+   float front_ambient[4]  = { 0.2, 0.2, 0.2, 0.0 };
+   float front_diffuse[4]  = { 0.95, 0.95, 0.8, 0.0 };
+   float front_specular[4] = { 0.6, 0.6, 0.6, 0.0 };
+   glMaterialfv(GL_FRONT, GL_EMISSION, front_emission);
+   glMaterialfv(GL_FRONT, GL_AMBIENT, front_ambient);
+   glMaterialfv(GL_FRONT, GL_DIFFUSE, front_diffuse);
+   glMaterialfv(GL_FRONT, GL_SPECULAR, front_specular);
+   glMaterialf(GL_FRONT, GL_SHININESS, 16.0);
+   glColor4fv(front_diffuse);
+
+   glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
+   glEnable(GL_CULL_FACE);
+   glColorMaterial(GL_FRONT, GL_DIFFUSE);
+   glEnable(GL_COLOR_MATERIAL);
+
+   glEnable(GL_LIGHTING);
+   glShadeModel(GL_SMOOTH);
+}
+
+
+void setUpFonts(int numFontFiles)
+{
+   /* The total number of fonts is styles * faces */
+   totalFonts = numFontFiles*NumStyles;
+   
+   /* Allocate an array to hold all fonts */
+   fonts = new FTFont *[totalFonts];
+   
+   for (int faceIdx = 0;faceIdx < numFontFiles;faceIdx++)
+   {
+      fonts[faceIdx*NumStyles + FTGL_BITMAP] = new FTGLBitmapFont( fontfiles[faceIdx] );
+      fonts[faceIdx*NumStyles + FTGL_PIXMAP] = new FTGLPixmapFont( fontfiles[faceIdx] );
+      fonts[faceIdx*NumStyles + FTGL_OUTLINE] = new FTGLOutlineFont( fontfiles[faceIdx] );
+      fonts[faceIdx*NumStyles + FTGL_POLYGON] = new FTGLPolygonFont( fontfiles[faceIdx] );
+      fonts[faceIdx*NumStyles + FTGL_EXTRUDE] = new FTGLExtrdFont( fontfiles[faceIdx] );
+      fonts[faceIdx*NumStyles + FTGL_TEXTURE] = new FTGLTextureFont( fontfiles[faceIdx] );
+   
+      for( int x = 0; x < NumStyles; ++x)
+      {
+         int fontIdx = faceIdx*NumStyles + x;
+         
+         if( fonts[fontIdx]->Error())
+         {
+            fprintf( stderr, "Failed to open font %s\n", fontfiles[faceIdx] );
+            exit(1);
+         }
+         
+         if( !fonts[fontIdx]->FaceSize( 24))
+         {
+            fprintf( stderr, "Failed to set size\n");
+            exit(1);
+         }
+      
+         fonts[fontIdx]->Depth(20);
+         
+         fonts[fontIdx]->CharMap(ft_encoding_unicode);
+      }
+   } /* Instantiate and configure named fonts (for faceIdx) */
+   
+	infoFont = new FTGLPixmapFont( fontfiles[0]);
+	
+	if( infoFont->Error())
+	{
+		fprintf( stderr, "Failed to open font %s\n", fontfiles[0]);
+		exit(1);
+	}
+	
+	infoFont->FaceSize( 18);
+
+   strcpy(myString,"OpenGL is a powerful software interface for graphics hardware that allows graphics programmers to produce high-quality color images of 3D objects. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+}
+
+
+void renderFontmetrics()
+{
+	float x1, y1, z1, x2, y2, z2;
+   if (layouts[currentLayout]) {
+      layouts[currentLayout]->BBox(myString, x1, y1, z1, x2, y2, z2);
+   } else {
+      fonts[current_font]->BBox( myString, x1, y1, z1, x2, y2, z2);
+   } /* If there is a layout use it to compute the bbox, otherwise query as a string (if/else layouts[]) */
+  
+	// Draw the bounding box
+	glDisable( GL_LIGHTING);
+	glDisable( GL_TEXTURE_2D);
+			glEnable( GL_LINE_SMOOTH);
+			glEnable(GL_BLEND);
+			glBlendFunc( GL_SRC_ALPHA, GL_ONE); // GL_ONE_MINUS_SRC_ALPHA
+   
+	glColor3f( 0.0, 1.0, 0.0);
+	// Draw the front face
+	glBegin( GL_LINE_LOOP);
+		glVertex3f( x1, y1, z1);
+		glVertex3f( x1, y2, z1);
+		glVertex3f( x2, y2, z1);
+		glVertex3f( x2, y1, z1);
+	glEnd();
+	// Draw the back face
+	if( (GetStyle() == FTGL_EXTRUDE) && (z1 != z2))
+	{
+		glBegin( GL_LINE_LOOP);
+			glVertex3f( x1, y1, z2);
+			glVertex3f( x1, y2, z2);
+			glVertex3f( x2, y2, z2);
+			glVertex3f( x2, y1, z2);
+		glEnd();
+	// Join the faces
+		glBegin( GL_LINES);
+			glVertex3f( x1, y1, z1);
+			glVertex3f( x1, y1, z2);
+			
+			glVertex3f( x1, y2, z1);
+			glVertex3f( x1, y2, z2);
+			
+			glVertex3f( x2, y2, z1);
+			glVertex3f( x2, y2, z2);
+			
+			glVertex3f( x2, y1, z1);
+			glVertex3f( x2, y1, z2);
+		glEnd();
+	}
+	
+   if (!layouts[currentLayout]) {
+		/* There is no layout. Draw the baseline, Ascender and Descender */
+      glBegin( GL_LINES);
+         glColor3f( 0.0, 0.0, 1.0);
+         glVertex3f( 0.0, 0.0, 0.0);
+         glVertex3f( fonts[current_font]->Advance( myString), 0.0, 0.0);
+         glVertex3f( 0.0, fonts[current_font]->Ascender(), 0.0);
+         glVertex3f( 0.0, fonts[current_font]->Descender(), 0.0);
+      glEnd();
+   } else if (layouts[currentLayout] && (dynamic_cast <FTSimpleLayout *>(layouts[currentLayout]))) {
+      float lineWidth = ((FTSimpleLayout *)layouts[currentLayout])->GetLineLength();
+      
+      /* The layout is a simple layout.  Render guides that mark the edges of the wrap region */
+      glColor3f(0.5,1.0,1.0);
+      glBegin( GL_LINES);
+         glVertex3f( 0, 10000, 0);
+         glVertex3f( 0,-10000, 0);
+         glVertex3f( lineWidth, 10000, 0);
+         glVertex3f( lineWidth,-10000, 0);
+      glEnd();
+   } /* Render layout specific metrics (if/elseif layouts[currentLayout]) */
+		
+	
+	// Draw the origin
+	glColor3f( 1.0, 0.0, 0.0);
+	glPointSize( 5.0);
+	glBegin( GL_POINTS);
+		glVertex3f( 0.0, 0.0, 0.0);
+	glEnd();
+}
+
+
+void renderFontInfo()
+{
+    glMatrixMode( GL_PROJECTION);
+    glLoadIdentity();
+    gluOrtho2D(0, w_win, 0, h_win);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+
+	// draw mode
+	glColor3f( 1.0, 1.0, 1.0);
+	glRasterPos2f( 20.0f , h_win - ( 20.0f + infoFont->Ascender()));
+
+	switch( mode)
+	{
+		case EDITING:
+			infoFont->Render("Edit Mode");
+			break;
+		case INTERACTIVE:
+			break;
+	}
+	
+	// draw font type
+	glRasterPos2i( 20 , 20);
+	switch(GetStyle())
+	{
+		case FTGL_BITMAP:
+			infoFont->Render("Bitmap Font");
+			break;
+		case FTGL_PIXMAP:
+			infoFont->Render("Pixmap Font");
+			break;
+		case FTGL_OUTLINE:
+			infoFont->Render("Outline Font");
+			break;
+		case FTGL_POLYGON:
+			infoFont->Render("Polygon Font");
+			break;
+		case FTGL_EXTRUDE:
+			infoFont->Render("Extruded Font");
+			break;
+		case FTGL_TEXTURE:
+			infoFont->Render("Texture Font");
+			break;
+	}
+	
+	glRasterPos2f( 20.0f , 20.0f + infoFont->Ascender() - infoFont->Descender());
+	infoFont->Render(fontfiles[GetFace()]);
+   
+   if (layouts[currentLayout] && (dynamic_cast <FTSimpleLayout *>(layouts[currentLayout]))) { 
+      glRasterPos2f( 20.0f , 20.0f + 2*(infoFont->Ascender() - infoFont->Descender()));
+      switch (((FTSimpleLayout *)layouts[currentLayout])->GetAlignment()) {
+         case FTSimpleLayout::ALIGN_LEFT: infoFont->Render("Align Left"); break;
+         case FTSimpleLayout::ALIGN_RIGHT: infoFont->Render("Align Right"); break;
+         case FTSimpleLayout::ALIGN_CENTER: infoFont->Render("Align Center"); break;
+         case FTSimpleLayout::ALIGN_JUST: infoFont->Render("Align Justified"); break;
+      } /* Output the alignment mode of the layout (switch GetAlignment()) */
+   } /* If the current layout is a simple layout output the alignemnt mode (if layouts[currentLayout]) */
+}
+
+void do_display (void)
+{
+	switch( GetStyle() )
+	{
+		case FTGL_BITMAP:
+		case FTGL_PIXMAP:
+		case FTGL_OUTLINE:
+			break;
+		case FTGL_POLYGON:
+			glDisable( GL_BLEND);
+			setUpLighting();
+			break;
+		case FTGL_EXTRUDE:
+			glEnable( GL_DEPTH_TEST);
+			glDisable( GL_BLEND);
+			setUpLighting();
+			break;
+		case FTGL_TEXTURE:
+			glEnable( GL_TEXTURE_2D);
+			glDisable( GL_DEPTH_TEST);
+			setUpLighting();
+			glNormal3f( 0.0, 0.0, 1.0);
+			break;
+
+	}
+
+	glColor3f( 1.0, 1.0, 1.0);
+// If you do want to switch the color of bitmaps rendered with glBitmap,
+// you will need to explicitly call glRasterPos (or its ilk) to lock
+// in a changed current color.
+
+   if (layouts[currentLayout])
+   {
+      layouts[currentLayout]->Render(myString);
+   }
+   else
+   {
+      fonts[current_font]->Render( myString);
+   } /* If there is an active layout use it to render the font (if/else layouts[currentLayout]) */
+   
+   renderFontmetrics();
+   renderFontInfo();
+}
+
+
+void display(void)
+{
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+   	SetCamera();
+	
+	switch( GetStyle())
+	{
+		case FTGL_BITMAP:
+		case FTGL_PIXMAP:
+			glRasterPos2i((long)( w_win / 2 + OX),(long)( h_win / 2 + OY));
+			glTranslatef(w_win / 2 + OX,h_win / 2 + OY, 0.0);
+			break;
+		case FTGL_OUTLINE:
+		case FTGL_POLYGON:
+		case FTGL_EXTRUDE:
+		case FTGL_TEXTURE:
+         glTranslatef(OX,OY,0);
+			tbMatrix();
+			break;
+	}
+	
+	glPushMatrix();
+
+	do_display();
+
+	glPopMatrix();
+	
+    glutSwapBuffers();
+}
+
+
+void myinit( int numFontFiles)
+{
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glClearColor( 0.13, 0.17, 0.32, 0.0);
+	glColor3f( 1.0, 1.0, 1.0);
+	
+	glEnable( GL_CULL_FACE);
+	glFrontFace( GL_CCW);
+	
+	glEnable( GL_DEPTH_TEST);
+	
+	glEnable( GL_POLYGON_OFFSET_LINE);
+	glPolygonOffset( 1.0, 1.0); // ????
+	 	
+	SetCamera();
+
+	tbInit(GLUT_LEFT_BUTTON);
+	tbAnimate( GL_FALSE);
+
+   setUpFonts( numFontFiles);
+    
+   /* Configure the simple layout */
+   simpleLayout.SetLineLength(InitialLineLength);
+   simpleLayout.SetFont(fonts[current_font]);
+}
+
+
+void parsekey(unsigned char key, int x, int y)
+{
+	switch (key)
+	{
+		case 27: exit(0); break;
+		case 13:
+			if( mode == EDITING)
+			{
+				mode = INTERACTIVE;
+			}
+			else
+			{
+				mode = EDITING;
+				carat = 0;
+			}
+			break;
+      case '\t':
+         if (layouts[currentLayout] && (dynamic_cast <FTSimpleLayout *>(layouts[currentLayout]))) {
+            FTSimpleLayout *simpleLayout = (FTSimpleLayout *)layouts[currentLayout];
+            switch (simpleLayout->GetAlignment()) {
+               case FTSimpleLayout::ALIGN_LEFT: 	simpleLayout->SetAlignment(FTSimpleLayout::ALIGN_RIGHT); break;
+               case FTSimpleLayout::ALIGN_RIGHT: 	simpleLayout->SetAlignment(FTSimpleLayout::ALIGN_CENTER); break;
+               case FTSimpleLayout::ALIGN_CENTER:	simpleLayout->SetAlignment(FTSimpleLayout::ALIGN_JUST); break;
+               case FTSimpleLayout::ALIGN_JUST: 	simpleLayout->SetAlignment(FTSimpleLayout::ALIGN_LEFT); break;
+            } /* Decrement the layout (switch GetAlignemnt()) */
+         } /* If the current layout is a simple layout change it's alignment properties (if simpleLayout) */
+         break;
+		default:
+			if( mode == INTERACTIVE)
+			{
+				myString[0] = key;
+				myString[1] = 0;
+				break;
+			}
+			else
+			{
+				myString[carat] = key;
+				myString[carat + 1] = 0;
+				carat = carat > 2000 ? 2000 : ++carat;
+			}
+	}
+
+	glutPostRedisplay();
+
+}
+
+void parseSpecialKey(int key, int x, int y)
+{
+    FTSimpleLayout *simpleLayout = NULL;
+    if (layouts[currentLayout] && (dynamic_cast <FTSimpleLayout *>(layouts[currentLayout]))) {
+        simpleLayout = (FTSimpleLayout *)layouts[currentLayout];
+    } /* If the currentLayout is a simple layout store a pointer in simpleLayout (if layouts[currentLayout]) */
+
+    switch (key)
+    {
+        case GLUT_KEY_UP:
+            current_font = (GetFace()*NumStyles + ( current_font + 1)%NumStyles)%totalFonts;
+            break;
+        case GLUT_KEY_DOWN:
+            current_font = (GetFace()*NumStyles + ( current_font + NumStyles - 1)%NumStyles)%totalFonts;
+            break;
+        case GLUT_KEY_LEFT:
+            fonts[current_font]->FaceSize(fonts[current_font]->FaceSize() - 1);
+            break;
+        case GLUT_KEY_RIGHT:
+            fonts[current_font]->FaceSize(fonts[current_font]->FaceSize() + 1);
+            break;
+        case GLUT_KEY_PAGE_UP:
+            current_font = ( current_font + NumStyles)%totalFonts;
+            break;
+        case GLUT_KEY_PAGE_DOWN:
+            current_font = ( current_font + totalFonts - NumStyles)%totalFonts;
+            break;
+        case GLUT_KEY_HOME:
+            currentLayout = (currentLayout + 1)%NumLayouts;
+            break;
+        case GLUT_KEY_END:
+            currentLayout = (currentLayout + NumLayouts - 1)%NumLayouts;
+            break;
+        case GLUT_KEY_F1:
+        case GLUT_KEY_F10:
+            /* If the current layout is simple decrement its line length */
+            if (simpleLayout) simpleLayout->SetLineLength(simpleLayout->GetLineLength() - 10.0f);
+            break;
+        case GLUT_KEY_F2:
+        case GLUT_KEY_F11:
+            /* If the current layout is simple increment its line length */
+            if (simpleLayout) simpleLayout->SetLineLength(simpleLayout->GetLineLength() + 10.0f);
+            break;
+    }
+
+    if (simpleLayout) {
+        simpleLayout->SetFont(fonts[current_font]);
+    } /* If the current layout is a simple layout update it's font (if simpleLayout) */
+
+    glutPostRedisplay();
+}
+
+
+void motion(int x, int y)
+{
+    tbMotion( x, y);
+}
+
+void mouse(int button, int state, int x, int y)
+{
+    tbMouse( button, state, x, y);
+}
+
+void myReshape(int w, int h)
+{
+    glMatrixMode (GL_MODELVIEW);
+    glViewport (0, 0, w, h);
+    glLoadIdentity();
+
+    w_win = w;
+    h_win = h;
+    SetCamera();
+
+    tbReshape(w_win, h_win);
+}
+
+void SetCamera(void)
+{
+	switch( GetStyle())
+	{
+		case FTGL_BITMAP:
+		case FTGL_PIXMAP:
+			glMatrixMode( GL_PROJECTION);
+			glLoadIdentity();
+			gluOrtho2D(0, w_win, 0, h_win);
+			glMatrixMode(GL_MODELVIEW);
+			glLoadIdentity();
+			break;
+		case FTGL_OUTLINE:
+		case FTGL_POLYGON:
+		case FTGL_EXTRUDE:
+		case FTGL_TEXTURE:
+			glMatrixMode (GL_PROJECTION);
+			glLoadIdentity ();
+			gluPerspective( 90, (float)w_win / (float)h_win, 1, 1000);
+			glMatrixMode(GL_MODELVIEW);
+			glLoadIdentity();
+			gluLookAt( 0.0, 0.0, (float)h_win / 2.0f, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
+			break;
+	}	
+}
+
+
+int main(int argc, char *argv[])
+{
+   int numFontFiles;
+   
+	if ((argc >= 2) && !IGNORE_ARGV)
+   {
+      fontfiles = (char const **)argv + 1;
+      numFontFiles = argc - 1;
+   }
+   else
+   {
+      fontfiles = defaultFonts;
+      numFontFiles = NumDefaultFonts;
+   }
+
+	if (!fontfiles[0])
+	{
+		fprintf(stderr, "At least one font file must be specified on the command line\n");
+		exit(1);
+	}
+
+	glutInit( &argc, argv);
+    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE);
+	glutInitWindowPosition(50, 50);
+	glutInitWindowSize( w_win, h_win);
+	glutCreateWindow("FTGL TEST");
+	glutDisplayFunc(display);
+	glutKeyboardFunc(parsekey);
+   glutSpecialFunc(parseSpecialKey);
+	glutMouseFunc(mouse);
+    glutMotionFunc(motion);
+	glutReshapeFunc(myReshape);
+	glutIdleFunc(display);
+
+	myinit( numFontFiles);
+
+	glutMainLoop();
+
+	return 0;
+}
diff --git a/demo/Makefile.am b/demo/Makefile.am
index 837d20d..d99d191 100644
--- a/demo/Makefile.am
+++ b/demo/Makefile.am
@@ -1,6 +1,6 @@
 
 if HAVE_GLUT
-noinst_PROGRAMS = FTGLDemo
+noinst_PROGRAMS = FTGLDemo FTGLMFontDemo
 endif
 
 FTGLDemo_SOURCES = \
@@ -15,3 +15,15 @@ FTGLDemo_CXXFLAGS = $(FT2_CFLAGS) $(GL_CFLAGS)
 FTGLDemo_LDFLAGS = $(FT2_LIBS) $(GLUT_LIBS)
 FTGLDemo_LDADD = ../src/libftgl.la
 
+FTGLMFontDemo_SOURCES = \
+	FTGLMFontDemo.cpp \
+	tb.c \
+	tb.h \
+	trackball.c \
+	trackball.h \
+	$(NULL)
+FTGLMFontDemo_CPPFLAGS = -I$(top_srcdir)/include
+FTGLMFontDemo_CXXFLAGS = $(FT2_CFLAGS) $(GL_CFLAGS)
+FTGLMFontDemo_LDFLAGS = $(FT2_LIBS) $(GLUT_LIBS)
+FTGLMFontDemo_LDADD = ../src/libftgl.la
+
diff --git a/test/demo.cpp b/test/demo.cpp
index df51f7b..8287a81 100644
--- a/test/demo.cpp
+++ b/test/demo.cpp
@@ -13,7 +13,7 @@
 #include "FTGLTextureFont.h"
 #include "FTGLPixmapFont.h"
 
-#include "mmgr.h"
+//#include "mmgr.h"
 
 static FTFont* fonts[5];
 static int width;