This commit is contained in:
Song Minjae
2017-02-17 04:30:01 +09:00
parent fdefaf1bbc
commit 5d1e303785
16 changed files with 1551 additions and 14 deletions

View File

@@ -1,9 +1,9 @@
package net.torvald.imagefont
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.getPixel
import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
import org.newdawn.slick.opengl.Texture
import java.nio.ByteOrder
import java.util.*
/**
@@ -418,17 +418,38 @@ open class GameFontBase : Font {
drawString(x + xoff, y, printedBody, color)
}
private fun setBlendModeMul() {
GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
}
private fun setBlendModeNormal() {
GL11.glDisable(GL11.GL_BLEND)
Terrarum.appgc.graphics.setDrawMode(Graphics.MODE_NORMAL)
}
fun buildWidthTable(sheet: SpriteSheet, codeOffset: Int, codeRange: IntRange, rows: Int = 16) {
fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this)
/** @return Intarray(R, G, B, A) */
fun Texture.getPixel(x: Int, y: Int): IntArray {
val textureWidth = this.textureWidth
val hasAlpha = this.hasAlpha()
val offset = (if (hasAlpha) 4 else 3) * (textureWidth * y + x) // 4: # of channels (RGBA)
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
return intArrayOf(
this.textureData[offset].toUint(),
this.textureData[offset + 1].toUint(),
this.textureData[offset + 2].toUint(),
if (hasAlpha)
this.textureData[offset + 3].toUint()
else 255
)
}
else {
return intArrayOf(
this.textureData[offset + 2].toUint(),
this.textureData[offset + 1].toUint(),
this.textureData[offset].toUint(),
if (hasAlpha)
this.textureData[offset + 3].toUint()
else 255
)
}
}
val binaryCodeOffset = 15
val cellW = sheet.getSubImage(0, 0).width + 1 // should be 16