Jump to content
  • Advertisement
Sign in to follow this  
Ey-Lord

Displaying text always on top of the screen

This topic is 3614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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


Share this post


Link to post
Share on other sites
Yeah, thanxs, i should have done taht before ... and this way i minimize the number of changes in opengl matrices and states :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!