This topic is now archived and is closed to further replies.


Drawing Text

Recommended Posts

Enfekted    122
I just am finishing up switching my graphics engine from DirectX to OpenGL. Everything has gone smoothly up until I got to the font system. I think everything is loading correctly and all the settings are right for the camera, but no fonts are showing up at all. I'm loading the font like this
HRESULT CEGIFont::Initialize( HDC hDC, int nPointSize, LPCTSTR pFaceName )
	if ( m_bInitialized ) return E_FAIL;
	m_Base = glGenLists(96);
	m_hFont = CreateFont( nPointSize, 0, 0, 0, FW_NORMAL, false, false, false, 
						  FF_DONTCARE, pFaceName );

	if ( m_hFont == NULL ) return E_FAIL;

	SelectObject( hDC, m_hFont );
	if ( !wglUseFontOutlines( hDC, 0, 255, m_Base, 0, 50, WGL_FONT_POLYGONS, m_gmf ) )
		DWORD e = GetLastError();

//	InitializeDimensions( hDC );

	m_bInitialized = TRUE;
return true;

And printing a string with this
void CEGIFont::PrintString( int x, int y, char *String, COLORREF FontColor, UINT nFormat )
	if ( !String || !m_bInitialized ) return;

	float xPos = float(x);
	float yPos = float(y);
	float width = WidthOf( String );
	if ( nFormat == DT_RIGHT ) xPos = float(x-WidthOf( String ));
	else if ( nFormat == DT_CENTER ) xPos = float(x-(WidthOf( String )/2));

		glEnable( GL_COLOR_MATERIAL );
		glEnable( GL_CULL_FACE );


		glTranslatef( xPos, yPos, 0 );

		glColor3ub( GetRValue(FontColor), GetGValue(FontColor), GetBValue(FontColor) );				
		glPushAttrib( GL_LIST_BIT );
			glListBase( m_Base );
			glCallLists( GLsizei(strlen(String)), GL_UNSIGNED_BYTE, String );

		glDisable( GL_COLOR_MATERIAL );


And the world is initialized like this
void CGraphicSystem::SetView( RECT r)
	RECT cr;
	GetClientRect( m_hParent, &cr );
	glViewport( cr.left,, cr.right-cr.left, );

	glMatrixMode( GL_PROJECTION );
	glOrtho( r.left, r.right, r.bottom,, 100, -100 );
	glMatrixMode( GL_MODELVIEW );
	m_ViewRect = r;

// In CGraphicSystem::Init()

// ...

	glEnable( GL_BLEND );
	glEnable( GL_ALPHA_TEST );
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE );
	glEnable( GL_TEXTURE_2D );
	glShadeModel( GL_SMOOTH );
	glFrontFace( GL_CW );
	glAlphaFunc( GL_GREATER, 0 );
	RECT r;
	SetRect( &r, 0, 0, 1024, 768 );
	SetView( r );
// ...

If anyone can see what I'm doing wrong, please let me know. Thanks [edited by - enfekted on January 23, 2004 9:35:52 PM]

Share this post

Link to post
Share on other sites
shadow12345    100
-You don''t need material coloring for bitmap fonts, only for outline fonts

-You probably haven''t got the text lined up on the screen, I''d try using normal OpenGL projections by pushing the unit one unit farther into the screen than the close clipping plane by using glTranslatef, or just try setting it to 0,0 for the time being if you absolutely need to keep it in ortho

Share this post

Link to post
Share on other sites
Enfekted    122
thanks for the reply shadow.

This actually is a outline font.

I tried manually setting the position to {400,400,0} which is within the 0to1024 x 0to768 x -100to100 orthographic view, but no luck.

The only things I can think of is that the font is too small, the blending functions i set for my textures might be messing it up, or the fonts I'm using aren't supported in wglUseFontOutlines.

But, I tried scaling the text by 100x, removed all the glEnable() calls in Init(), and tried other true type fonts and nothing seems to work.

I'm out of ideas...

[edited by - enfekted on January 23, 2004 10:09:34 PM]

Share this post

Link to post
Share on other sites