use of de.matthiasmann.twl.utils.PNGDecoder in project chunkstories by Hugobros3.
the class CubemapGL method loadCubemapFromDisk.
public int loadCubemapFromDisk() {
bind();
ByteBuffer temp;
String[] names = { "right", "left", "top", "bottom", "front", "back" };
if (Client.getInstance().getContent().getAsset((name + "/front.png")) == null) {
logger().info("Can't find front.png from CS-format skybox, trying MC format.");
names = new String[] { "panorama_1", "panorama_3", "panorama_4", "panorama_5", "panorama_0", "panorama_2" };
}
try {
for (int i = 0; i < 6; i++) {
Asset pngFile = Client.getInstance().getContent().getAsset(name + "/" + names[i] + ".png");
if (pngFile == null)
throw new FileNotFoundException(name + "/" + names[i] + ".png");
PNGDecoder decoder = new PNGDecoder(pngFile.read());
temp = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(temp, decoder.getWidth() * 4, Format.RGBA);
temp.flip();
this.size = decoder.getHeight();
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, type.getInternalFormat(), decoder.getWidth(), decoder.getHeight(), 0, type.getFormat(), type.getType(), temp);
// Anti alias
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Anti seam
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
} catch (FileNotFoundException e) {
logger().warn("Couldn't find file : " + e.getMessage());
} catch (IOException e) {
logger().error("Failed to load properly cubemap : " + name);
}
return glId;
}
use of de.matthiasmann.twl.utils.PNGDecoder in project chunkstories by Hugobros3.
the class Texture2DAsset method loadTextureFromAsset.
public int loadTextureFromAsset() {
if (!Client.getInstance().getGameWindow().isMainGLWindow()) {
System.out.println("isn't main thread, scheduling load");
scheduledForLoad = true;
return -1;
}
scheduledForLoad = false;
// TODO we probably don't need half this shit
bind();
try {
InputStream is = asset.read();
PNGDecoder decoder = new PNGDecoder(is);
width = decoder.getWidth();
height = decoder.getHeight();
ByteBuffer temp = ByteBuffer.allocateDirect(4 * width * height);
decoder.decode(temp, width * 4, Format.RGBA);
is.close();
// ChunkStoriesLogger.getInstance().log("decoded " + width + " by " + height + " pixels (" + name + ")", ChunkStoriesLogger.LogType.RENDERING, ChunkStoriesLogger.LogLevel.DEBUG);
temp.flip();
bind();
glTexImage2D(GL_TEXTURE_2D, 0, type.getInternalFormat(), width, height, 0, type.getFormat(), type.getType(), (ByteBuffer) temp);
this.applyTextureWrapping();
this.applyFiltering();
this.computeMipmaps();
} catch (FileNotFoundException e) {
logger().warn("Couldn't find file : " + e.getMessage());
} catch (IOException e) {
logger().error("Error loading file : " + e.getMessage());
e.printStackTrace();
}
mipmapsUpToDate = false;
return glId;
}
use of de.matthiasmann.twl.utils.PNGDecoder in project chunkstories by Hugobros3.
the class Texture2DFile method loadTextureFromFile.
public int loadTextureFromFile() {
if (!Client.getInstance().getGameWindow().isMainGLWindow()) {
System.out.println("isn't main thread, scheduling load");
scheduledForLoad = true;
return -1;
}
scheduledForLoad = false;
// TODO we probably don't need half this shit
bind();
try {
InputStream is = new FileInputStream(file);
PNGDecoder decoder = new PNGDecoder(is);
width = decoder.getWidth();
height = decoder.getHeight();
ByteBuffer temp = ByteBuffer.allocateDirect(4 * width * height);
decoder.decode(temp, width * 4, Format.RGBA);
is.close();
// ChunkStoriesLogger.getInstance().log("decoded " + width + " by " + height + " pixels (" + name + ")", ChunkStoriesLogger.LogType.RENDERING, ChunkStoriesLogger.LogLevel.DEBUG);
temp.flip();
bind();
glTexImage2D(GL_TEXTURE_2D, 0, type.getInternalFormat(), width, height, 0, type.getFormat(), type.getType(), (ByteBuffer) temp);
this.applyTextureWrapping();
this.applyFiltering();
this.computeMipmaps();
} catch (FileNotFoundException e) {
logger().warn("Couldn't find file : " + e.getMessage());
} catch (IOException e) {
logger().error("Error loading file : " + e.getMessage());
e.printStackTrace();
}
mipmapsUpToDate = false;
return glId;
}
use of de.matthiasmann.twl.utils.PNGDecoder in project chunkstories by Hugobros3.
the class IconLoader method getByteBufferData.
ByteBuffer getByteBufferData(String name) {
try {
PNGDecoder decoder = new PNGDecoder(getClass().getResourceAsStream(name));
int width = decoder.getWidth();
int height = decoder.getHeight();
ByteBuffer temp = ByteBuffer.allocateDirect(4 * width * height);
decoder.decode(temp, width * 4, Format.RGBA);
temp.flip();
return temp;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of de.matthiasmann.twl.utils.PNGDecoder in project Terasology by MovingBlocks.
the class PNGTextureFormat method load.
@Override
public TextureData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
try (InputStream pngStream = inputs.get(0).openStream()) {
PNGDecoder decoder = new PNGDecoder(pngStream);
ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
buf.flip();
int height = decoder.getHeight();
int width = decoder.getWidth();
Texture.FilterMode filterMode = defaultFilterMode;
Texture.WrapMode wrapMode = Texture.WrapMode.CLAMP;
return new TextureData(width, height, new ByteBuffer[] { buf }, wrapMode, filterMode);
} catch (UnsupportedOperationException e) {
throw new IOException(e);
}
}
Aggregations