mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BitmapFont.cpp
Go to the documentation of this file.
1 
7 #include "BitmapFont.h"
8 
13  this->hDC = h;
14  this->m_size = 24;
15 }
16 
23  killFont();
24 }
25 
29 GLvoid BitmapFont::buildFont( GLvoid ) {
30  HFONT font; // Windows font-id
31  HFONT oldfont;
32 
33  base = glGenLists( 96 ); // create storage space for 96 characters
34 
35  font = CreateFont( -1*m_size, // height of the font
36  0, // width
37  0, // escapement angle
38  0, // orientation angle
39  0, // weight
40  FALSE, // italic
41  FALSE, // underline
42  FALSE, // strikeout
43  ANSI_CHARSET, // charset encoding
44  OUT_TT_PRECIS, // output precision
45  CLIP_DEFAULT_PRECIS, // clipping precision
46  ANTIALIASED_QUALITY, // anti aliasing
47  FF_DONTCARE | DEFAULT_PITCH, // family, pith
48  "Arial Narrow"); // the actual font
49 
50  oldfont = (HFONT)SelectObject( hDC, font );
51  wglUseFontBitmaps( hDC, 32, 96, base ); // builds 96 characters starting at character 32 (space)
52  SelectObject( hDC, oldfont );
53  DeleteObject( font );
54 }
55 
60 GLvoid BitmapFont::buildFont( GLuint size ) {
61  m_size = size;
62  this->buildFont();
63 }
64 
68 GLvoid BitmapFont::killFont( GLvoid ) {
69  glDeleteLists( base, 96 ); // delete all 96 characters
70 }
71 
77 GLvoid BitmapFont::print(const char *fmt, ...) {
78  char text[256];
79  va_list ap;
80 
81  if (fmt == NULL)
82  return;
83 
84  va_start(ap, fmt); // parse string for variables
85  vsprintf_s(text, fmt, ap); // convert symbols to numbers
86  va_end(ap); // store result
87 
88  glPushAttrib( GL_LIST_BIT ); // push the display list bits (we use them now)
89  glListBase(base - 32); // reset the base as we start only with char 32
90 
91  glCallLists((int)strlen(text), GL_UNSIGNED_BYTE, text); // draw string using display list
92  glPopAttrib(); // restore
93 }