This topic is now archived and is closed to further replies.


Fonts - Semi-NeHe Style!

Recommended Posts

Metus    168
Many greetings for NeHe who taught me OpenGL =). Now i have a question about his font (not bitmapped) tutorials. what if i want to load a fonts that''s NOT located in the systems "X:\Windows\font" directory but as a resource "Data\\Font.ttf". Is there any simple way to do this? because im moving from targa bitmapped fonts due to alpha channeling...

Share this post

Link to post
Share on other sites
NeHe    379
A few people have asked how to do this... If you have the NeHe CD, the code is on the disc (plug plug), if not, here is a small code snippet:

GLvoid BuildFont(GLvoid)
if (ok)
// Register a new font. (OTri - Perform automatic font registration.)
if( AddFontResource( aux ) == 1 )
bFontInstalled = true;
else bFontInstalled = false;
HFONT font;
lf.lfHeight = -24;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_BLACK;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = 0;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
strcpy( lf.lfFaceName, "YourCustomFont");
font = CreateFontIndirect( &lf );

// font = CreateFont( -24,0,0,0,FW_BLACK,FALSE,FALSE,FALSE,ANSI_CHARSET,0,0,0,FF_DONTCARE|DEFAULT_PITCH,"YourCustomFont");
SelectObject(hDC, font);

base = glGenLists(92);
if (index==0) wglUseFontOutlines(hDC,0,91,base,0.01f,0.1f,0,gmf);
else wglUseFontOutlines(hDC,0,91,base,0.0f,0.1f,0,gmf);

Hope it helps!!!

[edited by - NeHe on October 4, 2002 3:57:11 AM]

Share this post

Link to post
Share on other sites