00001
00002
00003 #include "SDL.h"
00004
00005 #include "SDL_opengl.h"
00006
00007 #include "FTGLTextureFont.h"
00008 #include "conversions.h"
00009 #include "log.h"
00010 #include "font_ftgl.h"
00011
00012
00013 using namespace std;
00014
00015 FontFTGL::FontFTGL(const char* file, int ptsize)
00016 {
00017
00018 mFont = new FTGLPixmapFont(file);
00019 if (!mFont || mFont->Error())
00020 {
00021 LOGE << "Loading font failed!" << endl;
00022 DIE();
00023 }
00024
00025 mFont->FaceSize(ptsize);
00026 }
00027
00028 FontFTGL::~FontFTGL()
00029 {
00030 if (mFont)
00031 {
00032 delete mFont;
00033 mFont = 0;
00034 }
00035 }
00036
00037 void FontFTGL::RenderUTF8(const std::string &utf8str, float x, float y)
00038 {
00039 TIN;
00040
00041 assertL(mFont != 0);
00042
00043
00044 wstring ws;
00045 utf8tows(utf8str.c_str(), ws);
00046
00047 glRasterPos2f(x, y);
00048 mFont->Render( ws.c_str());
00049 }
00050
00051
00052 int FontFTGL::Ascent()
00053 {
00054 assertL(mFont != 0);
00055 return (int)mFont->Ascender();
00056 }