更好的OpenGL字体渲染? [英] Better font rendering for OpenGL ?

查看:168
本文介绍了更好的OpenGL字体渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好''

我们正在为我们的应用程序使用特殊字体(用于GD& T表示法).

使用OpenGL渲染文本时,字体无法正确显示(与GDI甚至在Word中相比),所渲染字符串的字符之间还有一些额外的空格(1、2个像素).

我们正在执行的代码段,我们使用的是位图字体,我可能会发现是否有可能 hack 使用轮廓字体代替.

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.

推荐答案

我从未喜欢过位图字体在OpenGL中显示的方式.

在上一个项目中,我想尝试实现由
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.


另一种可能性是免费类型库.


您可以使用3d max或google sketch up(免费)为所需字体创建网格,并将其保存为3ds或obj格式,然后从您的应用程序中读取.渲染它..
简单明了吧?

jkchan
http://cgmath.blogspot.com
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


这篇关于更好的OpenGL字体渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆