Advertisement

drawing models changes my text color

Started by June 14, 2003 11:34 AM
3 comments, last by Karlj 21 years, 8 months ago
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
call the glcolor function before every print you make, or once for a bacht of prints. also i would add a glcolor in the draw function of your model, you dont need it but it might be usefull down the road when you dont want textures. you could also edit the glprint code to call color before rendering.

remember opengl is a state machine, once you change something like color it stays like that until you change it to something else
Advertisement
Im already doing that. I set the color just before I print,
every time.

There must be something else that the model draw code is doing.
Could it be loading a texture over my font? Can I disable
all textures just before I print my text without changing
tht things that I want to texture? Any ideas would help.

thanks!
Karl
Ok I fixed it by doing:
glDisable( GL_TEXTURE_2D );
just before my print, and
glEnable( GL_TEXTURE_2D );
just after the print.

Not sure if that is the right way, but it works.

Karl
You must disable texturing b4 printing bitmap fonts or else u will get weird colors.

This topic is closed to new replies.

Advertisement