Jump to content
  • Advertisement
Sign in to follow this  
diginerd

Text won't draw

This topic is 3496 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'm trying to get text to draw, but it won't. Here's how I set up the font:
HFONT oldFont;
HDC   hdc;
int  weight;

hdc = GRAPHICS.GetHDC();

m_base = glGenLists(96);

// Create the font
m_font = CreateFont(-size, 0, 0, 0, false, false, underline, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Times New Roman"); 

oldFont = (HFONT)SelectObject(hdc, m_font);		
wglUseFontBitmaps(hdc, 32, 96, m_base);			
SelectObject(hdc, oldFont);
DeleteObject(m_font);	


Here is how I render the text:
void TextManager::Render()
{
        int numText = m_textList.size();

	std::list<TextObject*>::iterator textBegin = m_textList.begin();
	std::list<TextObject*>::iterator textEnd   = m_textList.end();
	Font* temp;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, GFX_DEFAULT_WINDOW_WIDTH, 0, GFX_DEFAULT_WINDOW_HEIGHT, 1.0f, 100.0f);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	while(textBegin != textEnd)
	{
		// Only draw visible objects not marked
		// for deletion
		if(!(*textBegin)->m_visible)
		{
			++textBegin;
			continue;
		}

		// Clear the modelview stack
		glLoadIdentity();

		// Set color and screen position
		glColor4f((*textBegin)->m_color.x, (*textBegin)->m_color.y, (*textBegin)->m_color.z, (*textBegin)->m_color.w);
		glTranslatef(0.0f, 0.0f, -1.0f);
		glRasterPos2f((*textBegin)->m_pos.x, (*textBegin)->m_pos.y); 

		// Draw the text
		glPushAttrib(GL_LIST_BIT);

		temp = m_fontList[(*textBegin)->m_fontNum];
		glListBase(temp->m_base - 32);
		glCallLists(strlen((*textBegin)->m_text.c_str()), GL_UNSIGNED_BYTE, (*textBegin)->m_text.c_str());
		
		glPopAttrib();

		textBegin++;
	}

	glPopMatrix();

	CAMERA.SetProjection();
	CAMERA.SetModelView();

	CheckGLError();
}


If anyone sees something wrong with this code, I would greatly appreciate some help. Diginerd

Share this post


Link to post
Share on other sites
Advertisement
Did you forget to do these calls?

-----------------------
char text[256];
va_list ap;

va_start(ap, fmt);
vsprintf(text,fmt,ap);
va_end(ap);

-------------------

where fmt = a const char*

Share this post


Link to post
Share on other sites
I didn't read your code in depth but at a first glance it seems as if you render your text at z = -1. Your projection matrix is however set to near = 1, so the text is clipped (assuming the camera is located at z = 0). Since you have an ortho projection you can use near <= 0 (don't do that with perspective projection!).

Also you should not load the identity matrix within the while loop. Otherwise you'll overwrite your characters/lines, since they are at the same location (more or less).

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!