Sign in to follow this  
Ey-Lord

Displaying text always on top of the screen

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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)


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this