在OpenGL ES绘制文本(安卓) [英] Draw text in OpenGL ES (Android)

查看:574
本文介绍了在OpenGL ES绘制文本(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个小型的OpenGL游戏的Andr​​oid平台,我不知道如果有一个简单的方法来呈现在渲染帧的顶部文本(如HUD与player's成绩等)。该文本将需要使用自定义字体也。 我见过使用视图作为覆盖一个例子,但是我不知道如果我想这样做,因为我以后可能想将游戏到其他平台。 任何想法?

I'm currently developing a small OpenGL game for the Android platform and I wonder if there's an easy way to render text on top of the rendered frame (like a HUD with the player´s score etc). The text would need to use a custom font also. I've seen an example using a View as an overlay, but I don't know if I want to do that since I might want to port the game to other platforms later. Any ideas?

祺/每

推荐答案

Android的SDK不附带任何简单的方法来对OpenGL的看法绘​​制文本。让你有以下选项。

The Android SDK doesn't come with any easy way to draw text on OpenGL views. Leaving you with the following options.

  1. 将一个TextView在你的SurfaceView。这是缓慢的,坏的,但最直接的方法。
  2. 渲染常见字符串,纹理,和简单地画的纹理。这是目前为止最简单和最快的,但也是最不灵活的。
  3. 滚你自己的文本呈现$ C $基于精灵c。如果2是不是一种选择可能是第二个最好的选择。一个好方法,让你的脚湿,但注意,虽然看似简单(与基本特征是),它获得的为你添加更多的功能(纹理排列,处理换行符,可变宽度字体等更难,更具挑战性) - !如果你走这条路线,使之简单,只要你能逃脱​​
  4. 使用一个现成的,货架/开放源码库。有几个身边,如果你在寻找谷歌,较难的就是让他们的集成和运行。但至少,一旦你这样做,你将拥有所有的灵活性和成熟,他们提供的。
  1. Place a TextView over your SurfaceView. This is slow and bad, but the most direct approach.
  2. Render common strings to textures, and simply draw those textures. This is by far the simplest and fastest, but the least flexible.
  3. Roll-your-own text rendering code based on a sprite. Probably second best choice if 2 isn't an option. A good way to get your feet wet but note that while it seems simple (and basic features are), it get's harder and more challenging as you add more features (texture-alignment, dealing with line-breaks, variable-width fonts etc.) - if you take this route, make it as simple as you can get away with!
  4. Use an off-the-shelf/open-source library. There are a few around if you hunt on Google, the tricky bit is getting them integrated and running. But at least, once you do that, you'll have all the flexibility and maturity they provide.

这篇关于在OpenGL ES绘制文本(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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