Archived
0

[format code]

This commit is contained in:
2015-09-18 14:24:36 +03:00
parent bf0609c492
commit 8dbf4aa4ec
4 changed files with 134 additions and 136 deletions

View File

@@ -1,12 +1,12 @@
package ru.dmitriymx.lwjgl.tools;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
public class Tessellator {
private static Tessellator instance = new Tessellator();
private int draw_mode;
@@ -105,7 +105,7 @@ public class Tessellator {
}
}
public void removeDL(int displayListId){
public void removeDL(int displayListId) {
glDeleteLists(displayListId, 1);
}
@@ -169,7 +169,7 @@ public class Tessellator {
}
}
public void removeVBO(long vboData){
public void removeVBO(long vboData) {
glDeleteBuffers((int) (0b11111111 & vboData));
}
@@ -178,7 +178,6 @@ public class Tessellator {
boolean has_color = (0b11111111 & vboData >>> 24) == 1;
boolean has_texture = (0b11111111 & vboData >>> 32) == 1;
if (has_color) {
glEnableClientState(GL_COLOR_ARRAY);
// 12L -> 3 << 2
@@ -209,7 +208,7 @@ public class Tessellator {
public void startDrawingUseVA(int drawMode) {
use_va = true;
draw_mode = drawMode;
use_color = false; //TODO а надоли? есть же reset()
use_color = false; // TODO а надоли? есть же reset()
use_texture = false;
}
@@ -263,8 +262,10 @@ public class Tessellator {
glDrawArrays(draw_mode, 0, vertex_count);
if (use_texture) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (use_color) glDisableClientState(GL_COLOR_ARRAY);
if (use_texture)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (use_color)
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

View File

@@ -1,13 +1,13 @@
package ru.dmitriymx.lwjgl.tools;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
public class Texture {
private static boolean set_blend = false;
private int bind_id;
@@ -82,7 +82,7 @@ public class Texture {
public static void setAlpha(boolean alpha) {
if (alpha) {
glEnable(GL_BLEND);
if (!set_blend){
if (!set_blend) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
set_blend = true;
}
@@ -109,8 +109,7 @@ public class Texture {
image.getRGB(0, 0, width, height, rgb_array, 0, width);
imageData.put(rgb_array);
imageData.position(0).limit(rgb_array_size);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8_REV, imageData);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, imageData);
}
private void prepare_onePixel() {

View File

@@ -31,7 +31,8 @@ public class FontEngine {
public final int visual_bounds_width, visual_bounds_height, visual_bounds_x, visual_bounds_y;
public final int width_char;
private CharData(int texture_offset_x, int texture_offset_y, int visual_bounds_width, int visual_bounds_height, int visual_bounds_x, int visual_bounds_y, int width_char) {
private CharData(int texture_offset_x, int texture_offset_y, int visual_bounds_width, int visual_bounds_height, int visual_bounds_x,
int visual_bounds_y, int width_char) {
this.texture_offset_x1 = glyphTexture.floatX(texture_offset_x);
this.texture_offset_y1 = glyphTexture.floatY(texture_offset_y);
this.texture_offset_x2 = glyphTexture.floatX(texture_offset_x + visual_bounds_width);
@@ -76,16 +77,6 @@ public class FontEngine {
glyphTexture = new Texture(createBlankImage());
}
// public void initializeString(String string) {
// char[] chars = string.toCharArray();
// for (char chr : chars) {
// if (!charMap.containsKey(chr)) {
// cache_char(chr, true);
// }
// }
// glyphTexture.updateTexture();
// }
public Font getFont() {
return font;
}
@@ -108,7 +99,8 @@ public class FontEngine {
}
}
if (needUpdTexture) glyphTexture.updateTexture();
if (needUpdTexture)
glyphTexture.updateTexture();
}
public FontMetrics getFontMetrics() {
@@ -127,7 +119,8 @@ public class FontEngine {
return image;
}
// Добавляем символ в "базу": рисуем на текстуре и сохраняем метрические данные
// Добавляем символ в "базу": рисуем на текстуре и сохраняем метрические
// данные
private void putChar(char chr) {
CharData data = drawChar(chr);
texture_offset_char_x += data.visual_bounds_width + 1;
@@ -154,7 +147,8 @@ public class FontEngine {
}
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, ~visualBounds.y + 1, widthChar);
return new CharData(texture_offset_char_x, texture_offset_char_y, visualBounds.width, visualBounds.height, ~visualBounds.x + 1,
~visualBounds.y + 1, widthChar);
}
// Увеличиваем вместимость текстуры путем увеличения ее размеров.

View File

@@ -1,16 +1,16 @@
package ru.dmitriymx.lwjgl.tools.fontengine;
import static org.lwjgl.opengl.GL11.*;
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};
private float[] color4f = new float[] { 1f, 1f, 1f, 1f };
public SimpleText(String string, FontEngine engine) {
this.engine = engine;
@@ -52,10 +52,14 @@ public class SimpleText implements Renderable {
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);
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;
}