OpenGL纹理映射字体渲染
我正在 OpenGL 中实现一个简单的字体渲染器,并且有几个问题,
它基本上将带有字符的图像加载到 OpenGL 纹理中
最好有一个带有所有字符的大纹理,或者我可以每个角色也有一个纹理?
使用大纹理,我似乎无法弄清楚如何正确地从纹理上绘制一个带有一个字符的四边形。
假设整个纹理是 256 * 256,每个字符是 16 * 16
我想绘制一个 16 * 16 的四边形并将纹理中的一个字符映射到它上面
我尝试过 glTexCoord2f()
但这仅适用于 0-1 的范围
I'm implementing a simple font renderer in OpenGL and have a few questions regarding that
It basically loads an image with characters on them into an OpenGL texture
Is it better to have one big texture with all characters on it, or can I have one texture per character as well?
Using the big texture, I can't seem to figure out how to correctly draw a quad with one character from the texture on it.
Let's say the whole texture is 256 * 256, and each character is 16 * 16
I want to draw a quad which is 16 * 16 and map one character from the texture on it
I have tried glTexCoord2f()
but that only works with ranges from 0-1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.- 对于所有角色来说,使用一个大纹理会更好地提高性能。这称为纹理图集。
2.- 要获取纹理坐标,请将像素坐标转换为纹理坐标除以宽度和高度。例如,像素 (16, 16) 具有纹理坐标 (16 / 256.0, 16 / 256.0)。
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).