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

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

问题描述

我想搞清楚一个简单的在OpenGL中绘制一些文本。我的研究表明它是一个相当复杂的任务。它包括创建(或在运行时生成)字体atlas纹理,然后为每个字母创建一个只有正确的位置和纹理坐标的四边形。



一些好的东西关于freetype,但是发现很少关于如何让它运行在iPhone上,它似乎是相当复杂。



因此有任何Objective- C包装的OpenGL文本库,与人们一直在使用的iPhone SDK?

解决方案

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



我在一个预处理中做所有的字体解析步骤(所有在C#在Windows上,因为它发生)。图谱本身是生成的,只包含所需的字符 - 为了减少空间,我有时最终生成多个单一的图谱来保持纹理大小pow2和一个明智的决议。



您可以轻松地从freetype中提取字形信息。传递到你的应用程序与纹理在运行时,然后它是相当微不足道的只是改变纹理的UV坐标所需。



这是值得的,这是我如何定义一个字形字符在我的小引擎:

  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; //到Y轴的距离

u32 m_horiAdvance; //总计水平前进这个字符需要

u32 m__tpage_index; //这个glyph使用哪个tpage?

};

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



我同意这一切似乎是一个很重要的工作,一个相当琐碎的问题,但我发现它给了我很多灵活性,真的没有花很长时间来实现,当我下定决心。



如果你需要任何其他细节,请随意回复或评论。 (祝你好运:)






回复你的评论, / p>

查看freetype文档,它基本上给你的字形数据,而不会搞乱,它只是拉出它的字体。至于纹理本身,你得到freetype来渲染每个字形,然后管理它来构建纹理。



这是我的工具代码的一个摘录,它实现了这一点: http://pastebin.com/md1c6354



请注意,这只是为了对我的眼睛,而不是为了公共消费,所以请原谅它是混乱的地狱:)


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.

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.

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?

解决方案

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.

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.

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?

};

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...

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.

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 :)

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

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