OK, I was able to get TexFont to work by ignoring the example logic from the author’s web page and just using my noggin to setup the OGL environment how I thought it should be… and it worked.
So, this site has the source files and the documentation:
http://www.opengl.org/developers/code/mjktips/TexFont/TexFont.html
The license is a “do whatever you want with this- but it is not in the public domain” strange type of license. I guess he just doesn’t want it showing up in someone’s book or technical paper without his permission. But it is free for use in commercial applications.
With the following wrapper logic you should be able to get it working with SDL. Note that if you support resizable windows or a toggle to and from full screen, you have to recall the txfEstablishTexture() routine on the font after the resize/toggle event. You can just call the “InitFont()” wrapper routine that I provide here and it should be cool. One may also want to consider deleting the texture objects and the TexFont structure before the resize/toggle event, since the destruction and recreation of an OpenGL context that occurs with an additional call to SDL_SetVideoMode() may end up leaving the texture object that is the bitmapped font dangling.
------------------------------------ code starts here -----------------------------------------
BOOL InitFont( VOID );
BOOL FontRender( CHAR *string );
TexFont *gCurrTexturedFont = NULL;
// ------------------------------------------------------------------------------------------------------
BOOL InitFont( VOID )
{
CHAR *fontStr = “C:\Blake\HGS\txf\times_medium.txf”;
if (!gCurrTexturedFont)
{
gCurrTexturedFont = txfLoadFont( fontStr );
if (!gCurrTexturedFont)
{
fprintf( stderr, “Problem loading %s, %s\n”, fontStr, txfErrorString() );
return FALSE;
}
}
txfEstablishTexture( gCurrTexturedFont, 0, GL_TRUE );
return TRUE;
}
// ------------------------------------------------------------------------------------------------------
BOOL FontRender( CHAR *string )
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
INT32 stringLen = strlen( string );
INT32 width, ascent, descent;
txfGetStringMetrics( gCurrTexturedFont, string, stringLen, &width, &ascent, &descent);
glPushMatrix();
INT32 x = (INT32)(-width * 0.5f), y = 0;
glTranslatef( (float)x, (float)y, 0.0f );
// note that I use a +z is “up” type of coordinate system,
// therefore I need to rotate by 90 in X before rendering any text…
glRotatef( 90.0f, 1.0f, 0.0f, 0.0f );
glColor3f( 0.2f, 0.2f, 0.9f );
txfRenderString( gCurrTexturedFont, string, stringLen );
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
return TRUE;
}
------------------------------------ code ends here -----------------------------------------
Slight side note: while looking up the address to the TexFont home page I can across this:
http://nate.scuzzy.net/programming/gltexfont/gltexfontdoc.html
http://nate.scuzzy.net/programming/gltexfont/
which is another OpenGL font library with a very similar name but different features. It allows meta characters within the string to turn on and off italics and possibly other neato stuff. But since I got TexFont to work, I did not really persue it.
Back on the TexFont topic, this site here:
http://plib.sourceforge.net/fnt/index.html
is a GLUT based OpenGL font library by Steve Baker that also reads the same “.fnt” files as TexFont, and that version distributes about a dozen example fonts that you can use with TexFont. So if you use TexFont you may want to grab those also. On the home page for TexFont there is an X based utility that generates new TexFonts, but since I’m developing on Win32 I can’t use it. If anyone working within an X environment does happen to start using the GenTexFont utility, I would appreciate them passing any useful fonts my way.
good luck,
-Blake