0

我正在 OpenGL 中实现一个简单的字体渲染器,对此有一些疑问

它基本上将带有字符的图像加载到OpenGL纹理中

  • 有一个大纹理,上面有所有字符会更好,还是每个字符也可以有一个纹理?

  • 使用大纹理,我似乎无法弄清楚如何从纹理中正确绘制一个带有一个字符的四边形。

假设整个纹理是256 * 256,每个字符是16 * 16

我想绘制一个 16 * 16 的四边形并从其上的纹理映射一个字符

我已经尝试过glTexCoord2f(),但这仅适用于 0-1 的范围

4

1 回答 1

3

1.- It's better for performance to have one big texture with all the characters. This is called a Texture Atlas.

2.- To get the texture coordinates, convert from pixel coords to texture coords dividing by the width and height. For example, pixel (16, 16) has texture coords (16 / 256.0, 16 / 256.0).

于 2010-10-16T15:53:00.840 回答