public static BufferedImage convertToImage(TextureRegion textureRegion) { final int width = textureRegion.getWidth(); final int height = textureRegion.getHeight(); final Rect2i pixelRegion = textureRegion.getPixelRegion(); final Texture texture = textureRegion.getTexture(); ByteBuffer textureBytes = texture.getData().getBuffers()[0]; int stride = texture.getWidth() * 4; int posX = pixelRegion.minX(); int posY = pixelRegion.minY(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int r = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4)); int g = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 1)); int b = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 2)); int a = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 3)); int argb = (a << 24) + (r << 16) + (g << 8) + b; image.setRGB(x, y, argb); } } return image; }
public static MeshData generateIconMeshData(TextureRegion tex, int alphaLimit, boolean withContour, Vector4f colorContour) { ByteBuffer buffer = tex.getTexture().getData().getBuffers()[0]; int posY = pixelRegion.minY(); int stride = tex.getTexture().getWidth() * 4;
@Override public void drawTexture(TextureRegion texture, Color color, ScaleMode mode, Rect2i absoluteRegion, float ux, float uy, float uw, float uh, float alpha) { if (!texture.getTexture().isLoaded()) { return; textureMat.setTexture("texture", texture.getTexture()); textureMat.setFloat4("color", color.rf(), color.gf(), color.bf(), color.af() * alpha); textureMat.bindTextures();
@Override public void drawTextureBordered(TextureRegion texture, Rect2i region, Border border, boolean tile, float ux, float uy, float uw, float uh, float alpha) { if (!texture.getTexture().isLoaded()) { return; textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height()); textureMat.setTexture("texture", texture.getTexture()); textureMat.setFloat4("color", 1, 1, 1, alpha); textureMat.bindTextures();