Many years ago I purchased the C++ series, and to start with I would like to say a big thank you to Jason and Joel - Thanks to your teachings I am now in a solid career with a decent salary.
Although I watched the C++ series minus the OpenGL videos many years ago, I have come back to study, and work my way through the OpenGL series as I always intended to; now is the right time for that as I have noticed a massive gap in the market and lots of money to be made for a certain app.
So I am currently working my way through the videos, and as many others might have noticed, when pulling in a font file the equation to work through each character set is not quite right - you get a load of weird Ascii characters printing instead of the ones you intended.
The video algorithm (GLEngine::buildTextureFont):
Code:
GLvoid GLEngine::buildTextureFont( GLvoid )
{
this->fontBase = glGenLists( 256 );
glBindTexture( GL_TEXTURE_2D, this->fontTexture->texID );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
for( int i=0; i<256; i++ )
{
GLfloat cx = (GLfloat)(i % 16) / 16.0f;
GLfloat cy = (GLfloat)(i / 16) / 16.0f;
glNewList( this->fontBase+i, GL_COMPILE );
glBegin( GL_QUADS );
glTexCoord2f( cx, 1.0f - cy - 0.0625f ); glVertex2i( 0, fontSize );
glTexCoord2f( cx + 0.0625f, 1.0f - cy - 0.0625f ); glVertex2i( fontSize, fontSize );
glTexCoord2f( cx + 0.0625f, 1.0f - cy ); glVertex2i( fontSize, 0 );
glTexCoord2f( cx, 1.0f - cy ); glVertex2i( 0, 0 );
glEnd();
glTranslated( fontSpace, 0, 0 );
glEndList();
}
}
My corrections:
Code:
GLvoid GLEngine::buildTextureFont( GLvoid )
{
this->fontBase = glGenLists( 256 );
glBindTexture( GL_TEXTURE_2D, this->fontTexture->texID );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
for( int i=0; i<256; i++ )
{
GLfloat cx = (GLfloat)(i % 16) / 16.0f;
GLfloat cy = (GLfloat)((255-i) / 16) / 16.0f;
glNewList( this->fontBase+i, GL_COMPILE );
glBegin( GL_QUADS );
glTexCoord2f( cx, 1.0f - cy - 0.0625f ); glVertex2i( 0, 0 );
glTexCoord2f( cx + 0.0625f, 1.0f - cy - 0.0625f ); glVertex2i( fontSize, 0 );
glTexCoord2f( cx + 0.0625f, 1.0f - cy ); glVertex2i( fontSize, fontSize );
glTexCoord2f( cx, 1.0f - cy ); glVertex2i( 0, fontSize );
glEnd();
glTranslated( fontSpace, 0, 0 );
glEndList();
}
}
I hope many others find this post useful, and save each of you scratching your heads for hours.