Archived
0

fix: Bug regenerate texture in FontEngine class

This commit is contained in:
2015-09-21 12:08:27 +03:00
parent 65d8a40a51
commit acc146d06a
2 changed files with 29 additions and 7 deletions

View File

@@ -27,7 +27,19 @@ public class Texture {
}
public void setImage(BufferedImage image) {
boolean recalc_onePixel = false;
if (getWidth() != image.getWidth() || getHeight() != image.getHeight()) {
recalc_onePixel = true;
}
this.image = image;
bind();
prepare_image(image);
if (recalc_onePixel) {
prepare_onePixel();
}
}
public void bind() {
@@ -53,7 +65,6 @@ public class Texture {
public void updateTexture() {
bind();
prepare_image(image);
prepare_onePixel();
}
public int getWidth() {

View File

@@ -20,7 +20,7 @@ import ru.dmitriymx.lwjgl.tools.Texture;
public class FontEngine {
private Font font;
private Texture glyphTexture;
private int texture_width = 128, texture_height = 128;
private int texture_width, texture_height;
private Graphics2D g2d;
private boolean anti_aliasing = false;
private Map<Character, CharData> charMap = new HashMap<>();
@@ -85,6 +85,10 @@ public class FontEngine {
glyphTexture.bind();
}
public Texture getGlyphTexture() {
return glyphTexture;
}
public CharData getCharData(char chr) {
return charMap.get(chr);
}
@@ -137,14 +141,19 @@ public class FontEngine {
FontMetrics fontMetrics = g2d.getFontMetrics();
int widthChar = fontMetrics.charWidth(chr) - visualBounds.x;
if (texture_offset_char_x >= texture_width || (texture_offset_char_x + visualBounds.width) > texture_width) {
texture_offset_char_y = max_height + 1;
texture_offset_char_x = 0;
}
if (texture_offset_char_y >= texture_height || (texture_offset_char_y + visualBounds.height) > texture_height) {
recreateGlyphTexture();
}
if (texture_offset_char_x >= texture_width || (texture_offset_char_x + visualBounds.width) > texture_width) {
texture_offset_char_y = max_height + 1;
texture_offset_char_x = 0;
}
}
g2d.drawGlyphVector(glyphVector, texture_offset_char_x - visualBounds.x, texture_offset_char_y - visualBounds.y);
return new CharData(texture_offset_char_x, texture_offset_char_y, visualBounds.width, visualBounds.height, ~visualBounds.x + 1,
@@ -165,13 +174,15 @@ public class FontEngine {
texture_offset_char_y = 0;
max_height = 0;
// установка новой текстуры
glyphTexture.setImage(img);
// отрисовка символов по новой
for (char chr : charMap.keySet()) {
putChar(chr);
}
// обновление текстуры
glyphTexture.setImage(img);
glyphTexture.updateTexture();
}
}