use of net.runelite.cache.definitions.TextureDefinition in project runelite by runelite.
the class TextureDumper method extract.
@Test
public void extract() throws IOException {
File base = StoreLocation.LOCATION, outDir = folder.newFolder();
int count = 0;
try (Store store = new Store(base)) {
store.load();
TextureManager tm = new TextureManager(store);
tm.load();
for (TextureDefinition texture : tm.getTextures()) {
Files.write(gson.toJson(texture), new File(outDir, texture.getId() + ".json"), Charset.defaultCharset());
++count;
}
}
logger.info("Dumped {} textures to {}", count, outDir);
}
use of net.runelite.cache.definitions.TextureDefinition in project runelite by runelite.
the class ModelViewer method getTexture.
private static Texture getTexture(int id) {
Texture texture = textures.get(id);
if (texture != null) {
return texture;
}
TextureDefinition td;
try (FileInputStream fin = new FileInputStream("textures/" + id + ".json")) {
td = new Gson().fromJson(new InputStreamReader(fin), TextureDefinition.class);
} catch (IOException ex) {
logger.warn(null, ex);
return null;
}
try (FileInputStream fin = new FileInputStream("sprite/" + td.getFileIds()[0] + "-0.png")) {
BufferedImage image = ImageIO.read(fin);
int width = image.getWidth();
int height = image.getHeight();
int[] rgb = new int[width * height];
int[] out = image.getRGB(0, 0, width, height, rgb, 0, width);
assert rgb == out;
ByteBuffer buffer = ByteBuffer.allocateDirect(rgb.length * 4);
for (int i = 0; i < rgb.length; ++i) {
int pixel = rgb[i];
// argb -> rgba
int a = pixel >>> 24;
int r = (pixel >> 16) & 0xff;
int g = (pixel >> 8) & 0xff;
int b = pixel & 0xff;
buffer.put((byte) r);
buffer.put((byte) g);
buffer.put((byte) b);
buffer.put((byte) a);
}
buffer.position(0);
int glTexture = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTexture);
// Setup filtering, i.e. how OpenGL will interpolate the pixels when scaling up or down
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Setup wrap mode, i.e. how OpenGL will handle pixels outside of the expected range
// Note: GL_CLAMP_TO_EDGE is part of GL12
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
// Linear Filtering
GL11.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
// Linear Filtering
GL11.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
texture = new Texture(rgb, width, height, glTexture);
textures.put(id, texture);
return texture;
} catch (IOException ex) {
logger.warn(null, ex);
return null;
}
}
Aggregations