www.pudn.com > mfcopentree.rar > MyFont.h
#if !defined MYFONT_H
#define MYFONT_H
/////////////////////////////////
/////My Fonts documents//////////
/////////////////////////////////
#include <windows.h>
#include <stdio.h> // Header File For Standard Input/Output
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
#include <stdarg.h> // Header File For Variable Argument Routines
class CMyFont
{
public:
char * buffer;
GLuint base;
GLuint list_number;
GLint fontheight;
public:
CMyFont()
{
list_number = 96;
fontheight = 24;
}
~CMyFont()
{
glDeleteLists(base, list_number);
}
////////////////////////////
///some necessary operations
////////////////////////////
void InitFont(HDC hDC, GLint height)
{
//when what you want are bitmap fonts, the initialization as following:
//NOTATION:
//YOU MUST DISABLE GL_TEXTURE_2D FIRST!!!
HFONT font; // Windows Font ID
fontheight = height;
base = glGenLists(96); // Storage For 96 Characters
font = CreateFont( -fontheight, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
CHINESEBIG5_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
"Arial"); // Font Name
SelectObject(hDC, font); // Selects The Font We Want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
}
//NOTATION:
//When you call this method ,you MUST call glDisable(GL_TEXTURE_2D)!!
//if you wanna show transparent effect, you must call glEnable(GL_DEPTH_TEST);
//and in the initialization partition, glBlendFunc(GL_SRC_ALPHA, GL_ONE).
void DisplayFonts(char *mystring, ...)
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (mystring == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, mystring); // Parses The String For Variables
vsprintf(text, mystring, 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();
}
};
#endif