0

我对 LWJGL 和使用位图字符的四边形纹理有疑问。我想显示一个大写的T。T 在第 6 行和第 5 列。这是X:40,Y:距离左上角32px。

我使用以下代码:

GL11.glTexCoord2f((float) (Math.floor(charID / this.charsInRow) * charSize) / bitmapSize, (float) (Math.floor(charID % this.charsInRow) * charSize) / bitmapSize);
GL11.glVertex2f((charPosition * fontSize) + x, y);
GL11.glTexCoord2f((float) (Math.floor(charID / this.charsInRow) * charSize + charSize) / bitmapSize, (float) (Math.floor(charID % this.charsInRow) * charSize) / bitmapSize);
GL11.glVertex2f((charPosition * fontSize) + x + fontSize, y);
GL11.glTexCoord2f((float) (Math.floor(charID / this.charsInRow) * charSize + charSize) / bitmapSize, (float) (Math.floor(charID % this.charsInRow) * charSize + charSize) / bitmapSize);
GL11.glVertex2f((charPosition * fontSize) + x + fontSize, y + fontSize);
GL11.glTexCoord2f((float) (Math.floor(charID / this.charsInRow) * charSize) / bitmapSize, (float) (Math.floor(charID % this.charsInRow) * charSize + charSize) / bitmapSize);
GL11.glVertex2f((charPosition * fontSize) + x
                            ,y + fontSize);

但是LWJGL从右下角开始计数,所以会显示一个奇怪的ASCII符号。

我该怎么做才能选择 T?

4

1 回答 1

1

OpenGL 归一化纹理坐标从左下角 (0,0) 开始,到右上角 (1,1)。在您的问题中,您使用错误的方法来解决您的字形 - 特别是,您应该从底部而不是顶部开始。

从您的示例图像来看,您的坐标可能应遵循以下格式:

Glyph Bottom Left: (X - <GlyphWidth>, <TextureResY> - Y - <GlyphHeight>)
Glyph Top Right:   (X,                <TextureResY> - Y                )

  其中 X 和 Y 分别为 40 和 32。

此外,您似乎已经调换了行和列。

于 2013-08-24T19:54:10.210 回答