Click here to Skip to main content
11,934,783 members (41,781 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ Windows OpenGL font

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);
	glFontListBase = 0;
glRasterPos3f( pos.x, pos.y, pos.z );
glListBase( glFontListBase);
glCallLists( strlen( text ), GL_UNSIGNED_BYTE, text );


Posted 28-Feb-12 8:14am
Edited 28-Feb-12 8:27am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Another possibility is the Free Type library.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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 ?


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 29 Feb 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100