unsigned int listBase;
unsigned int CreateBitmapFont(char *fontName, int fontSize, int fontWeight)
{
HFONT hFont;
unsigned int base;
base = glGenLists(96);
if(stricmp(fontName, "symbol") == 0)
{
hFont = CreateFont(fontSize, 0, 0, 0, fontWeight, 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, fontWeight, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);
}
if (!hFont)
return 0;
SelectObject(hDC, hFont);
wglUseFontBitmaps(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, FW_BOLD);
}
void RenderText()
{
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!");
}
Help please
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Bitmap Font problem
Ok now i made a Bitmap Font Generator and It compiled fine with no errors (after some debugging) however when i run it all i get is a blank screen. Heres the code.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
And what happen if you don''t call the PrintString function ? Do you have a black screen ? (you should)
Did you try tweaking the font parameters, eg get a smaller font size because the current one is probably too big and flushes the whole screen.
Did you try tweaking the font parameters, eg get a smaller font size because the current one is probably too big and flushes the whole screen.
Well if I don''t call PrintString I do get a black screen. I changed the size several times and no good so i''m still stumped. I''ll try downloading NeHe''s Bitmap Fonts and see if t runs.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Well NeHe''s work so what am I doing wrong.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
According to NeHe''s code, your code looks good.
The only difference is that he uses negative (-24) cell height whereas you use a positive one (48). You could try that.
If the screen if fully white, that means the polygons are drawn fully over the screen. You should try to resize the projection matrix to see when the white polygons do not entirely recover the screen.
You don''t show when you clear the buffers. I hope you call at each frame :
glClearColor(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Also, th problem could come from a few other lines of code that encapsulates the code you wrote. Expect to solve your problem probably out of the lines you showed.
The only difference is that he uses negative (-24) cell height whereas you use a positive one (48). You could try that.
If the screen if fully white, that means the polygons are drawn fully over the screen. You should try to resize the projection matrix to see when the white polygons do not entirely recover the screen.
You don''t show when you clear the buffers. I hope you call at each frame :
glClearColor(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Also, th problem could come from a few other lines of code that encapsulates the code you wrote. Expect to solve your problem probably out of the lines you showed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement