Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012
00013 #include "glut-demo/glut-demo.h"
00014 #include "glut-font/ftgl.h"
00015 #include "perf/perf.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 static void
00026 write
00027 (
00028 IN FTFont * font,
00029 IN const char * text
00030 )
00031 {
00032 ASSERT(font, "null");
00033 ASSERT(text, "null");
00034
00035 int dy = (int) (font->LineHeight() + 0.5);
00036
00037 font->Render(text);
00038
00039 glTranslatef(0, -(dy + 2), 0);
00040 }
00041
00042
00043
00044 class Drawer : public glut::DemoHost {
00045 public:
00046 Drawer(IN const char * path) {
00047 ASSERT(path, "null");
00048 m_fontPath = path;
00049 }
00050 ~Drawer(void) throw() { }
00051
00052
00053 void onInit(void) {
00054
00055 m_font = new FTGLTextureFont(m_fontPath.c_str());
00056 ASSERT(m_font, "out of memory");
00057
00058
00059 m_font->FaceSize(40);
00060 }
00061
00062 bool displayAxes(void) { return false; }
00063
00064 void display2D(IN int width, IN int height) {
00065 ASSERT(m_font, "null");
00066
00067 glColor3f(1.0, 0.5, 1.0);
00068
00069
00070 glMatrixMode(GL_MODELVIEW);
00071 glPushMatrix();
00072 glScalef(1, -1, 1);
00073 glTranslatef(16, -64, 0);
00074
00075
00076 write(m_font, "This is a test");
00077 write(m_font, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
00078 write(m_font, "abcdefghijklmnopqrstuvwxyz");
00079 write(m_font, "0123456789");
00080 write(m_font, "+-=[]{}|\\/<>,.!?\"'@#$%^&*()");
00081 write(m_font, "Hello World! Tread carefully...");
00082 write(m_font, "Four score and seven years ago,");
00083 write(m_font, "Isotope Au134");
00084 write(m_font, "You found a +3 backscratcher.");
00085 write(m_font, "This is not a true story");
00086 write(m_font, " ...but it could be.");
00087 glPopMatrix();
00088 }
00089
00090 private:
00091 std::string m_fontPath;
00092 smart_ptr<FTGLTextureFont> m_font;
00093 };
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 int
00104 main
00105 (
00106 IN int argc,
00107 IN const char * argv[]
00108 )
00109 {
00110 ASSERT(2 == argc, "Usage: ftgl-test <font-path>");
00111 const char * font_path = argv[1];
00112 DPRINTF("Using font path: '%s'", font_path);
00113
00114 try {
00115
00116 std::string title = "FTGL font test: ";
00117 title += font_path;
00118
00119
00120 smart_ptr<glut::DemoHost> host = new Drawer(font_path);
00121 ASSERT(host, "out of memory");
00122 glut::startDemo(argc, argv, title.c_str(), host);
00123
00124 } catch (std::exception& e) {
00125 DPRINTF("Exception: %s", e.what());
00126 }
00127
00128
00129 return -1;
00130 }
00131