该图像是一个 78*24 的字母图像,每个字母都是 6*6,所以总共 52 个正方形。
使用 glTexCoord 从图像中获取单个字母会不会有点乏味?
GL11.glTexCoord2f(0,0);
GL11.glTexCoord2f(0.0769f,0);
GL11.glTexCoord2f(0.0769f,0.25f);
GL11.glTexCoord2f(0,0.25f);
由于 78 的 1/13(0.0769) 是 6,而 24 的 1/4(0.25) 是 6,这就是我想要做的,挑出一个字母吗?我只是确定这是要走的路。
最佳答案
您可能想要编写一个函数/方法来创建单个字符的纹理坐标。由于您知道字符数以及尺寸,因此您可以将字符传递到该方法中,计算坐标并返回这些坐标,例如
Vector2D[] getCharacterCoords(char c) {
//calculate the coords with the knowledge that you have 78 * 24 pixels and a character is 6 * 6
//thus resulting in a 13 * 4 character grid.
//Note: since ASCII 'A' is code 65 and 'a' is 97 you'd need to subtract those values accordingly
}
关于java - OpenGL 与 glTexCoord - 具有许多图 block 的图像可能会变得乏味?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9877255/