在OpenGL ES中绘制文本 [英] Draw text in OpenGL ES

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

问题描述

我目前正在为Android平台开发一款小型OpenGL游戏,我想知道是否有一种简便的方法可以在渲染的帧上方渲染文本(例如带有玩家得分的HUD等).文本还需要使用自定义字体.

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.

有什么想法吗?

推荐答案

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. 在您的SurfaceView上放置一个TextView.这既缓慢又糟糕,但这是最直接的方法.
  2. 将常见的字符串渲染为纹理,然后简单地绘制这些纹理.这是迄今为止最简单,最快,但最不灵活的方法.
  3. 基于Sprite的滚动文本呈现代码.如果不选择2,可能是第二好的选择.弄湿脚的一种好方法,但请注意,虽然它看起来很简单(并且具有基本功能),但随着添加更多功能(纹理对齐,换行符,可变宽度字体等),它变得更加困难且更具挑战性. )-如果您选择这条路线,请尽量简化!
  4. 使用现成的/开放源代码库.如果您在Google上搜索,可能会有很多麻烦的地方是使它们集成并运行.但是至少,一旦这样做,您将拥有它们提供的所有灵活性和成熟度.
  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天全站免登陆