Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows OpenGL font
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 28-Feb-12 8:14am
Edited 28-Feb-12 8:27am
v2
Rate this: bad
good
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.
  Permalink  
Comments
Maximilien at 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 at 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
good
Please Sign up or sign in to vote.

Solution 2

Another possibility is the Free Type library.
  Permalink  
Rate this: bad
good
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 ?
 
jkchan
http://cgmath.blogspot.com
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 29 Feb 2012
Copyright © CodeProject, 1999-2014
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