OpenGL Text

Started by
3 comments, last by Running_Wolf 23 years, 2 months ago
I am trying to use the tutorial about bitmapped fonts to put the FPS of my application at the bottom of the screen. But the text won''t stay at the bottom. As you move around the world the text moves also. Sometimes you can''t even see it. When the text moves it moves somewhere betweent the center of the screen and the side. Or you just can''t see it.
L.I.G. == Life Is Good
Advertisement
You must not be making the appropriate openGL state changes during text drawing, this is the simple text class I wrote and use extensively:

  // "Text.h"class CText  {public:	CText(char *TexName, HDC *hDC);	virtual ~CText();	void Print(int x, int y, const char *fmt, ...);private:	unsigned int iBase;	HFONT Font;};// "Text.cpp"#include "Text.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CText::CText(char * TexName, HDC *hDC){		iBase = glGenLists(96);								// Storage For 96 Characters	Font = CreateFont(16,	// 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		TexName);                 // Font Name	SelectObject(*hDC, Font);     // Selects The Font We Want	wglUseFontBitmaps(*hDC, 32, 96, iBase);				// Builds 96 Characters Starting At Character 32}CText::~CText(){	glDeleteLists(iBase, 96);							// Delete All 96 Characters}void CText::Print(int x, int y, const char *fmt, ...){	char text[256];											va_list	ap;												if (fmt == NULL)											return;												va_start(ap, fmt);										    vsprintf(text, fmt, ap);						va_end(ap);								glDisable(GL_LIGHTING);	glDisable(GL_DEPTH_TEST);	glMatrixMode(GL_PROJECTION);							glPushMatrix();	glLoadIdentity();	glOrtho(0,640,0,480,-100,100);	glMatrixMode(GL_MODELVIEW);	glPushMatrix();	glLoadIdentity();	glTranslated(x,y,0);	glRasterPos2f(0, 0);	glPushAttrib(GL_LIST_BIT);							glListBase(iBase - 32);						glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	glPopAttrib();		glMatrixMode(GL_PROJECTION);	glPopMatrix();	glMatrixMode(GL_MODELVIEW);	glPopMatrix();		glEnable(GL_DEPTH_TEST);	glEnable(GL_LIGHTING);}  
Hi,

You must do :

glDisable(GL_DEPTH_TEST) before writing your text on the screen.


If you want, I''ve a litte example who display the FPS on the top left corner with a rotating cube ?

Interessted ???

Send me a mail to : dylan.leyder@ibelgique.com

Leyder Dylan

dylan.leyder@ibelgique.com

========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Or try the very good library and class here : http://nate.scuzzy.net/gltexfont
R U sure you reset the Modelview Matrix BEFORE printig the text?
If not, insert this one before your output code:

glLoadIdentity(); // Reset The Current Modelview Matrix
SnAkE''s Programming Resources

This topic is closed to new replies.

Advertisement