Original Post
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,
ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
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));
glPushMatrix();
glEnable( GL_COLOR_MATERIAL );
glEnable( GL_CULL_FACE );
glCullFace(GL_BACK);
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 );
glPopAttrib();
glDisable( GL_COLOR_MATERIAL );
glPopMatrix();
}
And the world is initialized like this
void CGraphicSystem::SetView( RECT r)
{
RECT cr;
GetClientRect( m_hParent, &cr );
glViewport( cr.left, cr.top, cr.right-cr.left, cr.bottom-cr.top );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( r.left, r.right, r.bottom, r.top, 100, -100 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
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 );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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]