Hi everyone, this is my first post here, hope you can help me.
I’m developing a game, and need to output text to the screen, however, so far I can’t seem to get it to work. I followed the tutorial (tutorial 13) on the NeHe site and have similar functions to the ones on there (BuildFont(), glPrint(“text”), KillFont() etc).
void BuildFont(GLvoid)
{
HFONT font;
base = glGenLists(96);
font = CreateFont( -14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Arial");
wglUseFontBitmaps(g_hDC, 32, 96, base);
SelectObject(g_hDC, font);
}
void KillFont(GLvoid)
{
glDeleteLists(base, 96);
}
void glPrint(const char *fmt, ...)
{
char text[256];
va_list ap;
if(fmt == NULL) {
return;
}
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
Once the font has been built, I’m using the following code to try and draw the text to the screen.
// draw all my graphics etc
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-1.0f);
glColor4f( 255, 0, 0, 1);
//glTranslatef(my_Camera.View().x, my_Camera.View().y, my_Camera.View().z);
glRasterPos2f(0.1f, 0.1f);
glPrint("SCORE:", score);
Any help/advice would be greatly appreciated. Also, i don’t know if this is related, but the camera is always moving in my game, along the Z axis, and rotating on the Y axis.
Thanks in advance.