mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 12:17:17 -04:00
Got the basics working.
This commit is contained in:
parent
f522f83781
commit
1ef1c9ce00
@ -1,5 +1,8 @@
|
||||
package li.cil.oc.client.renderer.font;
|
||||
|
||||
import li.cil.oc.util.FontUtil;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@ -40,7 +43,7 @@ public class FontParserUnifont implements IFontParser {
|
||||
if (glyph.length == 16) glyphWidth = 8;
|
||||
else if (glyph.length == 32) glyphWidth = 16;
|
||||
else return null;
|
||||
ByteBuffer buf = ByteBuffer.allocate(glyphWidth * 16 * 4);
|
||||
ByteBuffer buf = BufferUtils.createByteBuffer(glyphWidth * 16 * 4);
|
||||
for (byte aGlyph : glyph) {
|
||||
int c = ((int) aGlyph) & 0xFF;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
@ -49,6 +52,7 @@ public class FontParserUnifont implements IFontParser {
|
||||
c <<= 1;
|
||||
}
|
||||
}
|
||||
buf.rewind();
|
||||
return buf;
|
||||
}
|
||||
|
||||
@ -65,12 +69,12 @@ public class FontParserUnifont implements IFontParser {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
FontParserUnifont fpu = new FontParserUnifont();
|
||||
ByteBuffer buf = fpu.getGlyph("な".codePointAt(0));
|
||||
byte[] a = buf.array();
|
||||
for (int i = 0; i < a.length; i += 4) {
|
||||
if ((i % (a.length >> 4)) == 0 && i > 0) System.out.println("|");
|
||||
if (a[i] != 0) System.out.print("#");
|
||||
else System.out.print(" ");
|
||||
ByteBuffer buf = fpu.getGlyph(9829);
|
||||
System.out.println(FontUtil.wcwidth("a".codePointAt(0)));
|
||||
for (int i = 0; i < buf.capacity(); i += 4) {
|
||||
if ((i % (buf.capacity() >> 4)) == 0 && i > 0) System.out.println("|");
|
||||
if (buf.get(i) != 0) System.out.print("#");
|
||||
else System.out.print("話す ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -6,7 +6,7 @@ import org.lwjgl.opengl.GL11
|
||||
class DataCharRenderer extends DynamicCharRenderer {
|
||||
val parser = new FontParserUnifont()
|
||||
|
||||
override def canDisplay(c: Char) = true
|
||||
override def canDisplay(c: Char) = FontUtil.wcwidth(c) > 0 && parser.getGlyph(c) != null
|
||||
|
||||
override def charWidth: Double = parser.getGlyphWidth
|
||||
|
||||
@ -22,9 +22,9 @@ class DataCharRenderer extends DynamicCharRenderer {
|
||||
|
||||
val texture = GL11.glGenTextures()
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture)
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w, h, 0, GL11.GL_RGBA, GL11.GL_BYTE, parser.getGlyph(charCode))
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w, h, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, parser.getGlyph(charCode))
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST)
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST)
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR)
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS)
|
||||
GL11.glTexCoord2f(0, 1)
|
||||
|
@ -26,7 +26,7 @@ class DynamicFontRenderer(val charRenderer: DynamicCharRenderer) extends Texture
|
||||
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo)
|
||||
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, rbo)
|
||||
|
||||
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_RGBA8, charWidth, charHeight)
|
||||
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_RGBA8, charWidth * 2, charHeight)
|
||||
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL30.GL_RENDERBUFFER, rbo)
|
||||
|
||||
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0)
|
||||
@ -95,7 +95,7 @@ object DynamicFontRenderer {
|
||||
private val rows = size / cellHeight
|
||||
private val uStep = cellWidth / size.toFloat
|
||||
private val vStep = cellHeight / size.toFloat
|
||||
private val pad = 1f / size
|
||||
private val pad = 1.0 / size
|
||||
private val capacity = cols * rows
|
||||
|
||||
private var chars = 0
|
||||
@ -121,7 +121,7 @@ object DynamicFontRenderer {
|
||||
GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0)
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
GL11.glViewport(0, 0, w, h)
|
||||
GL11.glViewport(0, 0, owner.charWidth, h)
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION)
|
||||
GL11.glPushMatrix()
|
||||
@ -151,15 +151,15 @@ object DynamicFontRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
class CharIcon(val texture: CharTexture, val w: Float, val h: Float, val u1: Float, val v1: Float, val u2: Float, val v2: Float) {
|
||||
class CharIcon(val texture: CharTexture, val w: Int, val h: Int, val u1: Double, val v1: Double, val u2: Double, val v2: Double) {
|
||||
def draw(tx: Float, ty: Float) {
|
||||
GL11.glTexCoord2f(u1, v1)
|
||||
GL11.glTexCoord2d(u1, v1)
|
||||
GL11.glVertex2f(tx, ty + h)
|
||||
GL11.glTexCoord2f(u2, v1)
|
||||
GL11.glTexCoord2d(u2, v1)
|
||||
GL11.glVertex2f(tx + w, ty + h)
|
||||
GL11.glTexCoord2f(u2, v2)
|
||||
GL11.glTexCoord2d(u2, v2)
|
||||
GL11.glVertex2f(tx + w, ty)
|
||||
GL11.glTexCoord2f(u1, v2)
|
||||
GL11.glTexCoord2d(u1, v2)
|
||||
GL11.glVertex2f(tx, ty)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package li.cil.oc.server.component.machine.luac
|
||||
|
||||
import li.cil.oc.server.component.machine.NativeLuaArchitecture
|
||||
import li.cil.oc.util.ExtendedLuaState.extendLuaState
|
||||
import li.cil.oc.util.FontUtil
|
||||
|
||||
class UnicodeAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||
override def initialize() {
|
||||
@ -56,6 +57,18 @@ class UnicodeAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||
})
|
||||
lua.setField(-2, "upper")
|
||||
|
||||
lua.pushScalaFunction(lua => {
|
||||
lua.pushBoolean(FontUtil.wcwidth(lua.checkInteger(1)) > 1)
|
||||
1
|
||||
})
|
||||
lua.setField(-2, "isWide")
|
||||
|
||||
lua.pushScalaFunction(lua => {
|
||||
lua.pushInteger(FontUtil.wcwidth(lua.checkInteger(1)))
|
||||
1
|
||||
})
|
||||
lua.setField(-2, "charWidth")
|
||||
|
||||
lua.setGlobal("unicode")
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package li.cil.oc.server.component.machine.luaj
|
||||
|
||||
import li.cil.oc.server.component.machine.LuaJLuaArchitecture
|
||||
import li.cil.oc.util.FontUtil
|
||||
import li.cil.oc.util.ScalaClosure._
|
||||
import org.luaj.vm3.{LuaValue, Varargs}
|
||||
|
||||
@ -35,6 +36,12 @@ class UnicodeAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
|
||||
else LuaValue.valueOf(string.substring(start, end))
|
||||
})
|
||||
|
||||
unicode.set("isWide", (args: Varargs) =>
|
||||
LuaValue.valueOf(FontUtil.wcwidth(args.checkint(1)) > 1))
|
||||
|
||||
unicode.set("charWidth", (args: Varargs) =>
|
||||
LuaValue.valueOf(FontUtil.wcwidth(args.checkint(1))))
|
||||
|
||||
lua.set("unicode", unicode)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user