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()
.
.
.
Question about Bitmap Font!!!!
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!!!
ok, for the second time:
HDC g_HDC;
at the top of your file. outside of any brackets. to make it work, call GetDC( ) on the handle you get from CreateWindow( ) when you create it.
HDC g_HDC;
at the top of your file. outside of any brackets. to make it work, call GetDC( ) on the handle you get from CreateWindow( ) when you create it.
HWND your_window = CreateWindow(...);g_HDC = GetDC(your_window);
I'm so sorry to trouble you, but I cannot understand your code, can u explain it more in detail? how to call GetDC(), write what in it? ....emmm.....HWND is ....hhe...sorry for these troubles, or you can help me insert the general idea into my code, i am not sure put these coe into which part?? thanks a lot and best regards!!!!
[Edited by - koalacui on September 23, 2005 1:03:58 AM]
[Edited by - koalacui on September 23, 2005 1:03:58 AM]
You need the handle from your created window.
Pass it to GetDC(); the get the device context.
You can find a sample here.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
Pass it to GetDC(); the get the device context.
You can find a sample here.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement