26 lines
746 B
Java
26 lines
746 B
Java
package com.danitheskunk.skunkworks;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.IntBuffer;
|
|
|
|
abstract class BaseRenderContext implements IRenderContext {
|
|
public void drawString(Vec2i pos, String string, IFont font) {
|
|
int x = pos.getX();
|
|
int y = pos.getY();
|
|
IntBuffer buf;
|
|
try {
|
|
buf = ByteBuffer.wrap(string.getBytes("UTF-32")).asIntBuffer();
|
|
} catch(UnsupportedEncodingException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
for(int i = 0; i < string.length(); ++i) {
|
|
int ch = buf.get(i);
|
|
var tex = font.getTexture(ch);
|
|
var off = font.getOffset(ch);
|
|
drawTextureRectangle(new Recti(Vec2i.add(new Vec2i(x, y), off), tex.getSize()), tex);
|
|
x += font.getXAdvance(ch);
|
|
}
|
|
}
|
|
}
|