Jump to content
  • Advertisement
Sign in to follow this  

OpenGL font problems

This topic is 4141 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 everyone, I am trying to impliment a simple font for my engines demo (For ingame testing). This code is demo code, not engine code (Hence, its a little ugly) It is using OpenGL, and WGL for building the font. The problem is when I am trying to set the fonts color. Changing the fonts color not only changes the font, but the entire viewport to! Heres my code that creates and sets up the font..
class Font {

uint32_t _uiFontBase;

void Destroy () {

	glDeleteLists (_uiFontBase,96);


	virtual ~Font() {

		Destroy ();

void Build (HWND hwnd) {

	HFONT hFont, hOldFont;

	if (!win)

	// generate character lists (up to 96 characters)
	_uiFontBase = glGenLists (96);

	// Create our font
	hFont = CreateFont(	16,							// Height Of Font
						0,								// Width Of Font
						0,								// Angle Of Escapement
						0,								// Orientation Angle
						300,						// 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

	HDC hDC=GetDC(hwnd);
	hOldFont = (HFONT)SelectObject(hDC, hFont);
	wglUseFontBitmaps(hDC, 32, 96, _uiFontBase);				// Builds 96 Characters Starting At Character 32
	SelectObject(hDC, hOldFont);							// Selects The Font We Want
	DeleteObject(hFont);									// Delete The Font

void Print (std::string str) {

	glPushAttrib (GL_LIST_BIT);
	glListBase (_uiFontBase-32);
	glCallLists (str.length(), GL_UNSIGNED_BYTE, str.c_str());
	glPopAttrib ();

Font _font;

Here is the code that displays the font..
	glDisable (GL_TEXTURE_2D);

	glColor3f (0.0f,0.0f,1.0f);

	glRasterPos2f(-0.5f, -0.3f);
	_font.Print ("E v o l u t i o n E n g i n e");
        glRasterPos2f(-0.5f, -0.33f);
	char buf[255];
	sprintf_s (buf,"FPS: %i", uiFPS);
	_font.Print (buf);

	glEnable (GL_TEXTURE_2D);

(Ugly, I know--I have to clean up the demo) The text does display. Its the text color (glColor3f()) that seems to be causing the issue. Not only is the fonts color changed, but the entire viewport is as well: What could cause this? The text is supposed to be blue, and only the text. I know its probably something simple, I just cant find an answer.. Thanks!

Share this post

Link to post
Share on other sites
So, you called glColor3f to change the color of vertices to blue. Did you call it again to set the color back to white? Or did you leave it as is, so that all other vertices (including your level geometry) are also drawn using the last specified color — blue?

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!