Archived
0

create SimpleText

This commit is contained in:
2015-09-18 14:19:16 +03:00
parent 515059ffab
commit bf0609c492

View File

@@ -0,0 +1,66 @@
package ru.dmitriymx.lwjgl.tools.fontengine;
import org.lwjgl.util.Renderable;
import ru.dmitriymx.lwjgl.tools.Tessellator;
import static org.lwjgl.opengl.GL11.*;
public class SimpleText implements Renderable {
private Tessellator tess = Tessellator.getInstance();
private FontEngine engine;
private char[] chars;
private float[] color4f = new float[]{1f, 1f, 1f, 1f};
public SimpleText(String string, FontEngine engine) {
this.engine = engine;
}
public void setString(String string) {
this.chars = string.toCharArray();
engine.checkChars(chars);
}
public String getString() {
return String.valueOf(chars);
}
public void setColor(float red, float green, float blue, float alpha) {
this.color4f[0] = red;
this.color4f[1] = green;
this.color4f[2] = blue;
this.color4f[3] = alpha;
}
public float[] getColor() {
return color4f;
}
@Override
public String toString() {
return getClass().getCanonicalName() + "[" + getString() + "]";
}
@Override
public void render() {
engine.bindTexture();
float current_x = 0f;
tess.startDrawingUseVA(GL_QUADS);
for (char ch : chars) {
FontEngine.CharData charData = engine.getCharData(ch);
current_x -= charData.visual_bounds_x;
tess.setColor(color4f[0], color4f[1], color4f[2], color4f[3]).setTexture(charData.texture_offset_x1, charData.texture_offset_y1).addVertex(current_x, charData.visual_bounds_y, 0);
tess.setColor(color4f[0], color4f[1], color4f[2], color4f[3]).setTexture(charData.texture_offset_x2, charData.texture_offset_y1).addVertex(current_x + charData.visual_bounds_width, charData.visual_bounds_y, 0);
tess.setColor(color4f[0], color4f[1], color4f[2], color4f[3]).setTexture(charData.texture_offset_x2, charData.texture_offset_y2).addVertex(current_x + charData.visual_bounds_width, charData.visual_bounds_y - charData.visual_bounds_height, 0);
tess.setColor(color4f[0], color4f[1], color4f[2], color4f[3]).setTexture(charData.texture_offset_x1, charData.texture_offset_y2).addVertex(current_x, charData.visual_bounds_y - charData.visual_bounds_height, 0);
current_x += charData.width_char;
}
tess.drawVA();
}
}