Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Howdy'

We are using a specialized font for our application (for GD&T notations).

When rendering the text using OpenGL the font is not displayed properly (compared to GDI or even inside Word), there are some additional spaces (1, 2 pixels ) between characters of the rendered string.

Code snippet of what we are doing, we are using bitmap font, I might see if it is possible to hackuse in outline fonts instead.
// create the font and openGL list for he font
HDC hDC = wglGetCurrentDC();

LOGFONT logFont;
strcpy( logFont.lfFaceName, m_FontName );


CDC* cdc = GetDC();
HDC hdc = cdc->GetSafeHdc();

int pointPerInch = 72;
int deviceCaps = GetDeviceCaps( hdc, LOGPIXELSY );

logFont.lfHeight = -MulDiv(fontProperties.m_FontSize, deviceCaps, pointPerInch);
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = m_IsFontBold ? FW_BOLD : FW_REGULAR;
logFont.lfItalic = m_IsFontItalic ? TRUE : FALSE;
logFont.lfUnderline = FALSE;
logFont.lfStrikeOut = FALSE;
logFont.lfCharSet = DEFAULT_CHARSET;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = DEFAULT_QUALITY;
logFont.lfPitchAndFamily = FF_DONTCARE | FIXED_PITCH;

newfont = CreateFontIndirect(&logFont);
if (newfont) 
{
	SelectObject(hDC, newfont);
	glFontListBase = ::glGenLists(255);

	if (glFontListBase) 
	{
		::wglUseFontBitmaps(hDC, 0, 255, glFontListBase);
	} 

}
else
{
	glFontListBase = 0;
}

//...
glRasterPos3f( pos.x, pos.y, pos.z );
glListBase( glFontListBase);
glCallLists( strlen( text ), GL_UNSIGNED_BYTE, text );


Thanks.

Max.
Posted
Updated 28-Feb-12 7:27am
v2

I've never liked the way that bitmapped fonts show up in OpenGL.

In my last project, I had wanted to to try to implement the meshes created by D3DXCreateText(). I never got a chance to give that a go.

You can find it in the DirectX Samples.

It looks like a good solution for the windows platform.
 
Share this answer
 
Comments
Maximilien 28-Feb-12 14:07pm    
yeah, I don't think I'm ready to replace OpenGL with DirectX.(might be a good exercise though ... )
JackDingler 28-Feb-12 14:32pm    
I don't think you have to have a full blown DirectX app to use it.

My plan was to let it generate the meshes, then use them in OpenGL.
Another possibility is the Free Type library.
 
Share this answer
 
You can create meshes for the desired font in 3d max or google sketch up(free), and save it in 3ds or obj format, read it from your application.. Render it..
straightforward right ?

jkchan
http://cgmath.blogspot.com
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900