Displaying text always on top of the screen

Started by
1 comment, last by Ey-Lord 15 years, 5 months ago
Hey guys, i've got this little problem on my font rendering class : i can choosse the font, the color, th position of the string but it doesnt always stay on top the screen, sometimes some of my 3D object are in front of it :( It's meant to stay on top the screen( like UI text) here is my function where i draw a string :

void FontManager::DrawText2D(std::string FontName, unsigned int x, unsigned int y, const char *chaine, ...)
{ 
	glPushAttrib( GL_LIGHTING_BIT | GL_DEPTH_TEST | GL_TEXTURE_BIT );
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST) ;

	char texte[512]; 
	va_list argsPtr; 
	va_start(argsPtr, chaine); 
	vsprintf_s(texte, chaine, argsPtr); 
	va_end(argsPtr); 

	glMatrixMode(GL_PROJECTION); 
	glPushMatrix(); 
	glLoadIdentity();
	gluOrtho2D(0,Application::Instance().m_Settings.m_ScreenWidth,0,Application::Instance().m_Settings.m_ScreenHeight);

	glMatrixMode(GL_MODELVIEW); 
	glPushMatrix(); 
	glLoadIdentity(); 

	glPushAttrib(GL_LIST_BIT );
	glColor4f(1.0f, 0.0f, 0.0f,1.0f); 
	glRasterPos2f((GLfloat)x,(GLfloat)y);
	glListBase(m_Fonts2D[FontName].m_List); 
	glCallLists(strlen(texte), GL_UNSIGNED_BYTE, texte); 
	glPopAttrib();

	glPopMatrix(); 
	glMatrixMode(GL_PROJECTION); 
	glPopMatrix(); 
	glMatrixMode(GL_MODELVIEW);

	glPopAttrib();
}
I dont see where is the *hic* ...maybe you do :)
Advertisement
the safest way is to draw the text after youve drawn all the 3d stuff (and it will be faster than the method u have there since the state changes are gonna be far less)


Yeah, thanxs, i should have done taht before ... and this way i minimize the number of changes in opengl matrices and states :)

This topic is closed to new replies.

Advertisement