Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

OpenGLFont.cpp

Go to the documentation of this file.
00001 
00007 #include "OpenGLFont.h"
00008 
00009 OpenGLFont::OpenGLFont() {
00010         m_renderer = NULL;
00011         m_startTextModeList = 0;
00012         m_textBase = 0;
00013 }
00014 
00015 //OpenGLFont::OpenGLFont(const char *fontName, OpenGLRenderer *renderer, HDC hDC) {
00016 OpenGLFont::OpenGLFont(HFONT font, OpenGLRenderer *renderer, HDC hDC) {
00017         m_renderer = renderer;
00018         m_startTextModeList = 0;
00019         m_textBase = 0;
00020 
00021         //init(fontName, hDC);
00022         init(font, hDC);
00023 }
00024 
00025 OpenGLFont::~OpenGLFont() {
00026         m_renderer = NULL;
00027         if (m_textBase) glDeleteLists(m_textBase, 96);
00028         if (m_startTextModeList) glDeleteLists(m_startTextModeList, 1);
00029 
00030         LOG_SUCCESS(("Font removed"));
00031 }
00032 
00033 //bool OpenGLFont::init(const char *fontName, HDC hDC) {
00034 bool OpenGLFont::init(HFONT font, HDC hDC) {
00035         //HFONT font;
00036         HFONT oldfont;
00037 
00038         r = g = b = a = 1.0f;
00039 
00040         //if (!fontName)
00041         //      return false;
00042 
00043         m_textBase = glGenLists(96);
00044         if (!m_textBase) {
00045                 return false;
00046         }
00047 
00063         oldfont = (HFONT)SelectObject(hDC, font);
00064         wglUseFontBitmaps(hDC, 32, 96, m_textBase);
00065         SelectObject(hDC, oldfont);
00066 
00067         //DeleteObject(font);
00068 
00069         LOG_SUCCESS(("Font initialized"));
00070         return true;
00071 }
00072 
00073 void OpenGLFont::startTextMode() {
00074 
00075         // first call, create display list
00076         if (!m_startTextModeList) {
00077                 m_startTextModeList = glGenLists(1);
00078                 glNewList(m_startTextModeList, GL_COMPILE);
00079                 {
00080                         glListBase(m_textBase-32);
00081                         glMatrixMode(GL_PROJECTION);
00082                         glPushMatrix();
00083                         glLoadIdentity();
00084                         //if (g_fullscreen)
00085                         //      glOrtho(0, g_fullscreenWidth, g_fullscreenHeight, 0, -1, 1);
00086                         //else
00087                         //      gluOrtho2D(0, g_windowRight-g_windowLeft, g_windowBottom-g_windowTop, 0);       // this is bad...
00088                                 //glOrtho(g_windowLeft, g_windowRight, g_windowBottom, g_windowTop, -1, 1);
00089 
00090                         glOrtho(0, g_width, g_height, 0, -1, 1);
00091 
00092                         glMatrixMode(GL_MODELVIEW);
00093                         glPushMatrix();
00094                         glLoadIdentity();
00095                 }
00096                 glEndList();
00097         }
00098 
00099         glCallList(m_startTextModeList);
00100 
00101         m_renderer->setBlending(SRC_ALPHA, ONE);        // ONE_MINUS_SRC_ALPHA maby?
00102         m_renderer->setDepthFunc(DEPTH_NONE);
00103         m_renderer->apply();
00104 }
00105 
00106 void OpenGLFont::setColor(float rr, float gg, float bb, float aa) {
00107         r = rr;
00108         g = gg;
00109         b = bb;
00110         a = aa;
00111 }
00112 
00113 void OpenGLFont::print(float x, float y, const char *str, ...) {
00114         if (!m_textBase)
00115                 return;
00116 
00117         if(str==NULL)
00118                 return;
00119 
00120         static char text[256];
00121 
00122         va_list va;
00123         
00124         va_start(va, str);
00125         vsprintf(text, str, va);
00126         va_end(va);
00127 
00128         glColor4f(r, g, b, a);
00129         glPushAttrib(GL_LIST_BIT);              // can remove this?
00130         glRasterPos2f(x, y);
00131         glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
00132         glPopAttrib();                                  // can remove this?
00133 }
00134 
00135 void OpenGLFont::endTextMode() {
00136         glMatrixMode(GL_PROJECTION);
00137         glPopMatrix();
00138         glMatrixMode(GL_MODELVIEW);
00139         glPopMatrix();
00140 
00141         glListBase(0);
00142 }

Generated on Sun Jun 5 15:47:04 2005 for Defacto by  doxygen 1.4.3