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
| GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows font ID
HFONT oldfont; // Used for good house keeping
base = glGenLists(96); // Storage for 96 characters
font = CreateFont( -24, // Height of font
0, // Width of font
0, // Angle of escapement
0, // Orientation angle
FW_BOLD, // Font weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character set identifier
OUT_TT_PRECIS, // Output precision
CLIP_DEFAULT_PRECIS, // Clipping precision
ANTIALIASED_QUALITY, // Output quality
FF_DONTCARE|DEFAULT_PITCH, // Family and pitch
"Courier New"); // Font name
oldfont = (HFONT)SelectObject(hDC, font); // Selects the font we want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 characters starting at character 32
SelectObject(hDC, oldfont); // Selects the font we want
DeleteObject(font); // Delete the font
}
GLvoid KillFont(GLvoid) // Delete the font list
{
glDeleteLists(base, 96); // Delete all 96 characters
}
GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" routine
{
char text[256]; // Holds our string
va_list ap; // Pointer to list of arguments
if (fmt == NULL) // If there's no text
return; // Do nothing
va_start(ap, fmt); // Parses the string for variables
vsprintf(text, fmt, ap); // And converts symbols to actual numbers
va_end(ap); // Results are stored in text
glPushAttrib(GL_LIST_BIT); // Pushes the display list bits
glListBase(base - 32); // Sets the base character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws the display list text
glPopAttrib(); // Pops the display list bits
} |
Partager