Text won't draw

Started by
1 comment, last by Lord_Evil 15 years, 3 months ago
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
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*

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement