Hi i’m using outline fonts to display text. i’ve gone over nehe’s tutorial but for some reason it’s not showing up at all.
Here’s my code:
HDC hDC=NULL;
GLuint base; //for storing the font display list
GLfloat rotate;
GLYPHMETRICSFLOAT gmf[256]; //to store information about font
void createFont ()
{
HFONT font;
base = glGenLists(256); //generate display list ID for 256 char
font = CreateFont(-12, //height
1, //width
0, //escapement angle
0, //orientation angle
FW_BOLD, //font thickness
FALSE, FALSE, FALSE, // italic, underline, strikeout,
ANSI_CHARSET, //type of character set eg. CHINESEBIG5_CHARSET, GREEK_CHARSET
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, //precision and quality
FF_DONTCARE|DEFAULT_PITCH,
"Times New Roman"); //font name
SelectObject (hDC, font); //select the font
wglUseFontOutlines(hDC,
0, //starting character
255, //build 256 lists
base, //display list ID
0.0f, 0.2f, //font thickness
WGL_FONT_POLYGONS, //use polygons so that we can add lighting
gmf);
}
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
void releaseFont ()
{
glDeleteLists (base, 256);
}
void glPrint(char *text)
{
glPushAttrib(GL_LIST_BIT);
glListBase(base);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
void init ()
{
glClearColor(0,0,0,1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
createFont();
}
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0, 0, -10);
glColor3f(1, 1, 1);
glPrint("hi");
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("outline fonts");
init();
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutMainLoop();
}
Can someone please tell me what i’m doing wrong?