Original Post
Hi, guys, my first time to try bitmap font of OpenGL, i have tried a lot of ways, but still cannot display the font, this is the code, i write these code into AppMain.cpp file, and with 5 errors, it's all about g_HDC, i dont know how to solve it, can anybody help me on it!! thanks a lot and best regards!!!
unsigned int listBase;
.
.
.
unsigned int CreateBitmpFont(char *fontName, int fontSize)
{
HFONT hFont;
unsigned int base;
base = glGenLists(96);
if (stricmp(fontName, "symbol")== 0)
{
hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH,
fontName);
}
else
{
hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH,
fontName);
}
if (!hFont)
return 0;
SelectObject(g_HDC, hFont);
wglUseFontBitmaps(g_HDC, 32, 96, base);
return base;
}
void PrintString(unsigned int base, char *str)
{
if ((base == 0 || (str == NULL))
return;
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
glPopAttrib();
}
void ClearFont(unsigned int base)
{
if (base != 0)
glDeleteLists(base, 96);
}
void Initialize()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
listBase = CreateBitmapFont("Comic Sans MS", 48);
}
void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glRasterPos2f(-0.35f, 0.0f);
PrintString(listBase, "OpenGL Bitmap Fonts!");
glFlush();
SwapBuffers(g_HDC);
}
.
.
void main()
.
.
.