Im using a bitmapped font for text. I always set the
color to white using glColor3f(1.0f,1.0f,1.0f) just before
printing text. But my text is always colored based on the
colors used in the last model that I draw to the screen.
How do I make sure my text is always drawn white?
The text is printed using glPrint found in one of the
early lessons on bitmapped fonts.
GLvoid BuildFont() // Build Our Bitmap Font
{
HFONT font; // Windows font ID
HFONT oldfont; // Used for good house keeping
base = glGenLists(96); // Storage for 96 characters
font = CreateFont( -12, // Height of font
0, // Width of font
0, // Angle of escapement
0, // Orientation angle
FW_BOLD, // Font weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character set identifier
OUT_TT_PRECIS, // Output precision
CLIP_DEFAULT_PRECIS, // Clipping precision
ANTIALIASED_QUALITY, // Output quality
FF_DONTCARE|DEFAULT_PITCH, // Family and pitch
"Courier New"); // Font name
oldfont = (HFONT)SelectObject(g_window->hDC, font); // Selects the font we want
wglUseFontBitmaps(g_window->hDC, 32, 96, base); // Builds 96 characters starting at character 32
SelectObject(g_window->hDC, oldfont); // Selects the font we want
DeleteObject(font); // Delete the font
}
The models are drawn using code from the milkshape model lesson:
void Model::draw()
{
GLboolean texEnabled = glIsEnabled( GL_TEXTURE_2D );
// Draw by group
for ( int i = 0; i < m_numMeshes; i++ )
{
int materialIndex = m_pMeshes[i].m_materialIndex;
if ( materialIndex >= 0 )
{
glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient );
glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse );
glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular );
glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive );
glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess );
if ( m_pMaterials[materialIndex].m_texture > 0 )
{
glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture );
glEnable( GL_TEXTURE_2D );
}
else
glDisable( GL_TEXTURE_2D );
}
else
{
// Material properties?
glDisable( GL_TEXTURE_2D );
}
glBegin( GL_TRIANGLES );
{
for ( int j = 0; j < m_pMeshes[i].m_numTriangles; j++ )
{
int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
const Triangle* pTri = &m_pTriangles[triangleIndex];
for ( int k = 0; k < 3; k++ )
{
int index = pTri->m_vertexIndices[k];
glNormal3fv( pTri->m_vertexNormals[k] );
glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
glVertex3fv( m_pVertices[index].m_location );
}
}
}
glEnd();
}
if ( texEnabled )
glEnable( GL_TEXTURE_2D );
else
glDisable( GL_TEXTURE_2D );
}
Thanks!
Karl