使用自定义字体 OpenGL ES 的文本纹理
由于对 Opengl es(或 opengl)缺乏经验,我希望有人可以帮助我解决这个问题。
我正在创建一个 opengl es 应用程序,我希望能够动态创建按钮的文本等。
这样做的两个明显原因是:
- 模块化(无需使用 Photoshop 即可快速更改文本)
- 能够要稍后添加语言,
任何人都可以给我一个教程,或者至少给我基本步骤/功能:
创建纹理表单文本
加载自定义字体来显示文本具有所选自定义字体的纹理
指示我是否可以使用它来加载汉字?
最好的问候
杰森·罗杰斯
Having little experience in Opengl es (or opengl) I was hoping somebody could help me out with this.
I'm creating an opengl es application and I would like to be able to dynamically create the text of my buttons etc.
The 2 obvious reasons for that are:
-to be modular (changing the text quickly without using photoshop)
-to be able to add languages later down the line
can anybody point me to a tutorial or at least give me the basic steps/functions to:
create textures form text
load custom fonts to display text textures with the chosen custom font
indicate if I can use this for loading Kanji ?
Best regards
Jason Rogers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这是否是最好的方法,而且我以前没有这样做过......但我会这样做:
Paint
对象来描述对象的外观文本。Paint.setTypeFace()
)、大小(Paint.setTextSize()
)、颜色等所需参数。new Canvas(bitmap)
进行绘制。Canvas.drawText()
。当然,如果你想预先合成按钮背景/按钮文本,你可以使用画布绘制到背景中。
我认为无论 android 支持什么字体,Canvas.drawText() 都将支持使用适当的 Paint 设置,输入的字符串字符(汉字或其他)也应该如此。一旦您启动并运行了上述方法,通过实验就很容易找到答案。
希望这有点帮助。干杯,阿尔特。
I don't know if this is the best way, and I haven't done it before... but here's how I'd do it:
Paint
object that will describe the appearance of the text.Paint.setTypeFace()
), size (Paint.setTextSize()
), color, etc.Paint.getTextBounds()
and the string you want to draw.Bitmap.createBitmap()
, make sure it has an alpha component.new Canvas(bitmap)
.Canvas.drawText()
, using the paint object you created and the string you want.Bitmap.createScaledBitmap()
to be the next larger size as a power of 2 in x and y. I have a handy function (round up to power of 2) for that if you need it.GLUtils.texImage2D()
Of course, if you want to do the button background/button text compositing beforehand, you can use the canvas to draw into the background instead.
I presume that whatever fonts android supports, Canvas.drawText() will support using the appropriate Paint settings, the same should go for string characters (Kanji or other) that are input to it. It will be easy to find out by experimenting once you get the method above up and running.
Hope this was somewhat helpful. Cheers, Aert.
在我们的应用程序中,我们决定使用 android XML 布局而不是 OpenGL ES 来绘制 HUD(按钮、图标、文本)。
这样做有几个原因:
为此,您只需将
GlSurfaceView
作为子视图添加到主视图中。In our app we've decided to draw HUD (buttons, icons, text) using android XML layout instead of OpenGL ES.
There were severals reasons for that:
To do it you just need to add
GlSurfaceView
as a child view to your main view.