iPhone SDK 有没有像样的 OpenGL 文本绘图库? [英] Is there a decent OpenGL text drawing library for the iPhone SDK?

查看:22
本文介绍了iPhone SDK 有没有像样的 OpenGL 文本绘图库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出一个在 OpenGL 中绘制一些文本的简单方法.我的研究表明这是一项相当复杂的任务.它涉及创建(或在运行时生成)字体图集纹理,然后为每个字母创建一个具有正确位置和纹理坐标的四边形.

I'm trying to figure out a simple to draw some text in OpenGL. My research has shown its a fairly complex task. It involves creating (or generating at runtime) a font atlas texture, and then creating a quad for each letter with just the right placement and texture coordinates.

我听说过一些关于 freetype 的好消息,但对如何让它在 iPhone 上运行却知之甚少,而且它似乎相当复杂.

I've heard some good things about freetype, but have found very little about how to get it running on the iPhone, and it appears to be pretty complex.

那么,是否有任何 Objective-C 包装的 OpenGL 文本库可以与人们一直在使用的 iPhone SDK 一起使用?还是我只是想多了,我错过了一种更简单的方法?

So is there any Objective-C wrapped OpenGL text library that works with the iPhone SDK that people have been using? Or am I just over thinking this and there is an easier approach that I am missing?

推荐答案

您对使用 freetype 创建纹理图集以及所有字形信息的描述正是我在当前 iPhone 项目中所做的.

Your description of using freetype to create a texture atlas along with all the glyph information is exactly what I'm doing in my current iPhone project.

我在预处理步骤中对字体进行了所有解析(在 Windows 上全部使用 C#).地图集本身会生成并且仅包含所需的字符 - 为了减少空间,我有时也会生成多个地图集以保持纹理大小 pow2 和合理的分辨率.

I do all the parsing of the font in a pre-process step (All in C# on Windows as it happens). The atlas itself gets generated and contains only the characters needed - to cut down on space, I also sometimes end up generating more than a single atlas to keep textures sizes pow2 and of a sensible resolution.

您可以轻松地从 freetype 中提取字形信息.在运行时将其与纹理一起传递给您的应用程序,然后根据需要更改纹理的 UV 坐标相当简单.

You can easily pull out the glyph information from freetype. Pass that along to your app along with the textures at runtime and then it's fairly trivial to just alter the UV coords of the texture as required.

不管怎样,这就是我在我的小引擎中定义字形字符的方式:

For what it's worth, this is how I define a glyph character inside my little engine:

struct FontGlyph
{

u32 char_code;

u32 m_x;                // base x position on tpage

u32 m_y;            // base y position on tpage

u32 m_width;            // glyph width

u32 m_height;           // glyph height

i32 m_horiBearingX;     // Distance to X shift

i32 m_horiBearingY;     // Distance to Y shift

u32 m_horiAdvance;      // Total Horizontal advance this character requires

u32 m__tpage_index;     // Which tpage does this glyph use?

};

然后我有一个SpriteString"对象,它的行为与任何其他字符串非常相似,除了我可以使用精灵来绘制它......

I then have a 'SpriteString' object, which behaves pretty much like any other string, apart from I can draw it using sprites....

我同意这对于一个相当微不足道的问题来说似乎是一项艰巨的工作,但我发现它给了我很大的灵活性,而且当我开始着手时真的不需要那么长时间来实施.

I agree this all might seem like a big job for a fairly trivial problem, but I've found it's given me plenty of flexibility and really didn't take that long to implement when I got down to it.

如果您需要任何其他详细信息,请随时回复或发表评论.(祝你好运:)

Feel free to reply or comment if you need any other details. (And good luck :)

当我在评论部分的空间不足时回复您的评论...

Reply to your comment as I ran out of room in the comment section...

查看 freetype 文档,它基本上为您提供字形数据而不会弄乱,它只是将其从字体中提取出来.至于纹理本身,您可以使用 freetype 来渲染每个字形,然后对其进行管理以构建纹理.这是我作为一个完全独立于我的主应用程序的预处理来完成的.

Check out the freetype documentation, it basically gives you the glyph data without messing about, it just pulls it right out of the font. As for the textures themselves, you get freetype to render each glyph, and then manage that to build the texture. This I do as a pre-process entirely separate from my main app.

这是我执行此操作的工具代码的摘录:http://pastebin.com/md1c6354

Here's an excerpt of my tool code that does this: http://pastebin.com/md1c6354

但请注意,这只是为了我的眼睛而不是为了公众消费,所以请原谅它乱七八糟的事实:)

Please note though, this was only ever intended for my eyes and not for public consumption, so excuse the fact it's messy as hell :)

这篇关于iPhone SDK 有没有像样的 OpenGL 文本绘图库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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