Old school texture loading
Posted by
elect on
Feb 28, 2014; 1:50pm
URL: https://forum.jogamp.org/Old-school-texture-loading-tp4031754.html
Hi,
since TextureIO have some performances problems, (
http://stackoverflow.com/questions/1927419/loading-pngs-into-opengl-performance-issues-java-jogl-much-slower-than-c-sha) I would like to load textures from .PNG without it
If I try to load it like this
try {
File file = new File(getClass().getResource("/ec/data/textures/" + textureName).toURI());
bufferedImage = ImageIO.read(file);
ImageIO.write(bufferedImage, "png", byteArrayOutputStream);
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(EC_Mesh.class.getName()).log(Level.SEVERE, null, ex);
}
byte[] bs = byteArrayOutputStream.toByteArray();
texture = new int[1];
gl3.glGenTextures(1, texture, 0);
gl3.glBindTexture(GL3.GL_TEXTURE_2D, texture[0]);
{
gl3.glTexImage2D(GL3.GL_TEXTURE_2D, 0, GL3.GL_RGBA, bufferedImage.getWidth(), bufferedImage.getHeight(),
0, GL3.GL_RGBA, GL3.GL_UNSIGNED_BYTE, GLBuffers.newDirectByteBuffer(bs));I get an error
Caused by: java.lang.IndexOutOfBoundsException: Required 16777216 remaining bytes in buffer, only had 314199My png should be a 32b RGBA 2048x2048, then 4B aligned, then 2048 * 2048 * 4 = 16777216... so why do I get 314199?