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; package ru.dmitriymx.lwjgl.tools;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
public class Tessellator { public class Tessellator {
private static Tessellator instance = new Tessellator(); private static Tessellator instance = new Tessellator();
private int draw_mode; private int draw_mode;
@@ -178,7 +178,6 @@ public class Tessellator {
boolean has_color = (0b11111111 & vboData >>> 24) == 1; boolean has_color = (0b11111111 & vboData >>> 24) == 1;
boolean has_texture = (0b11111111 & vboData >>> 32) == 1; boolean has_texture = (0b11111111 & vboData >>> 32) == 1;
if (has_color) { if (has_color) {
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
// 12L -> 3 << 2 // 12L -> 3 << 2
@@ -263,8 +262,10 @@ public class Tessellator {
glDrawArrays(draw_mode, 0, vertex_count); glDrawArrays(draw_mode, 0, vertex_count);
if (use_texture) glDisableClientState(GL_TEXTURE_COORD_ARRAY); if (use_texture)
if (use_color) glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (use_color)
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);

View File

@@ -1,13 +1,13 @@
package ru.dmitriymx.lwjgl.tools; package ru.dmitriymx.lwjgl.tools;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
public class Texture { public class Texture {
private static boolean set_blend = false; private static boolean set_blend = false;
private int bind_id; private int bind_id;
@@ -109,8 +109,7 @@ public class Texture {
image.getRGB(0, 0, width, height, rgb_array, 0, width); image.getRGB(0, 0, width, height, rgb_array, 0, width);
imageData.put(rgb_array); imageData.put(rgb_array);
imageData.position(0).limit(rgb_array_size); imageData.position(0).limit(rgb_array_size);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, imageData);
GL_UNSIGNED_INT_8_8_8_8_REV, imageData);
} }
private void prepare_onePixel() { 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 visual_bounds_width, visual_bounds_height, visual_bounds_x, visual_bounds_y;
public final int width_char; 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_x1 = glyphTexture.floatX(texture_offset_x);
this.texture_offset_y1 = glyphTexture.floatY(texture_offset_y); this.texture_offset_y1 = glyphTexture.floatY(texture_offset_y);
this.texture_offset_x2 = glyphTexture.floatX(texture_offset_x + visual_bounds_width); this.texture_offset_x2 = glyphTexture.floatX(texture_offset_x + visual_bounds_width);
@@ -76,16 +77,6 @@ public class FontEngine {
glyphTexture = new Texture(createBlankImage()); 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() { public Font getFont() {
return font; return font;
} }
@@ -108,7 +99,8 @@ public class FontEngine {
} }
} }
if (needUpdTexture) glyphTexture.updateTexture(); if (needUpdTexture)
glyphTexture.updateTexture();
} }
public FontMetrics getFontMetrics() { public FontMetrics getFontMetrics() {
@@ -127,7 +119,8 @@ public class FontEngine {
return image; return image;
} }
// Добавляем символ в "базу": рисуем на текстуре и сохраняем метрические данные // Добавляем символ в "базу": рисуем на текстуре и сохраняем метрические
// данные
private void putChar(char chr) { private void putChar(char chr) {
CharData data = drawChar(chr); CharData data = drawChar(chr);
texture_offset_char_x += data.visual_bounds_width + 1; 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); 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,11 +1,11 @@
package ru.dmitriymx.lwjgl.tools.fontengine; package ru.dmitriymx.lwjgl.tools.fontengine;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.util.Renderable; import org.lwjgl.util.Renderable;
import ru.dmitriymx.lwjgl.tools.Tessellator; import ru.dmitriymx.lwjgl.tools.Tessellator;
import static org.lwjgl.opengl.GL11.*;
public class SimpleText implements Renderable { public class SimpleText implements Renderable {
private Tessellator tess = Tessellator.getInstance(); private Tessellator tess = Tessellator.getInstance();
private FontEngine engine; private FontEngine engine;
@@ -52,10 +52,14 @@ public class SimpleText implements Renderable {
FontEngine.CharData charData = engine.getCharData(ch); FontEngine.CharData charData = engine.getCharData(ch);
current_x -= charData.visual_bounds_x; 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_x1, charData.texture_offset_y1)
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); .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_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_x2, charData.texture_offset_y1)
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); .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; current_x += charData.width_char;
} }