redid font texture to include all ascii chars, even special chars for control characters since there was padding anyway and in particular umlaut chars and such; simplified initialization of renderer a tad, too

This commit is contained in:
Florian Nücke 2013-09-26 12:12:15 +02:00
parent cca693da31
commit 887a21941d
2 changed files with 15 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -30,40 +30,31 @@ object MonospaceFontRenderer {
// Set up the display lists.
{
// The font texture is 16x12, but chars are really only 10x12.
val charsPerRow = 16
val (charWidth, charHeight) = (MonospaceFontRenderer.fontWidth * 2, MonospaceFontRenderer.fontHeight * 2)
val uStep = 1.0 / charsPerRow
val vStep = 1.0 / 12 * 240 / 256 // Correct for padding at bottom.
val uOffset = uStep * 3 / 16
val uSize = uStep * 10 / 16
val vOffset = vStep * 1 / 20
val vSize = vStep * 18 / 20
val cols = 256 / charWidth
val uStep = charWidth / 256.0
val vStep = charHeight / 256.0
val t = Tessellator.instance
// Special case for whitespace: just translate, don't render.
GL11.glNewList(charLists + 32, GL11.GL_COMPILE)
GL11.glTranslatef(charWidth, 0, 0)
GL11.glEndList()
// Now create lists for all printable chars.
for (index <- (33 until 0x7F).union(0x9F until 0xFF)) {
// The font texture does not contain the 0-1F range, nor the 0x7F to
// 0x9F range (control chars as per Character.isISOControl).
val textureIndex =
(if (index - 32 >= 0x7F) index - (0x9F - 0x7F) else index) - 32
val x = textureIndex % charsPerRow
val y = textureIndex / charsPerRow
val u = x * uStep + uOffset
val v = y * vStep + vOffset
for (index <- 1 until 0xFF) {
val x = (index - 1) % cols
val y = (index - 1) / cols
val u = x * uStep
val v = y * vStep
GL11.glNewList(charLists + index, GL11.GL_COMPILE)
t.startDrawingQuads()
t.addVertexWithUV(0, charHeight, 0, u, v + vSize)
t.addVertexWithUV(charWidth, charHeight, 0, u + uSize, v + vSize)
t.addVertexWithUV(charWidth, 0, 0, u + uSize, v)
t.addVertexWithUV(0, charHeight, 0, u, v + vStep)
t.addVertexWithUV(charWidth, charHeight, 0, u + uStep, v + vStep)
t.addVertexWithUV(charWidth, 0, 0, u + uStep, v)
t.addVertexWithUV(0, 0, 0, u, v)
t.draw()
GL11.glTranslatef(charWidth, 0, 0)
GL11.glEndList()
}
// Special case for whitespace: just translate, don't render.
GL11.glNewList(charLists + ' ', GL11.GL_COMPILE)
GL11.glTranslatef(charWidth, 0, 0)
GL11.glEndList()
}
def drawString(value: Array[Char], x: Int, y: Int) = {