Re: How do I load texture array in jogl?
Posted by Steyrix on Aug 11, 2018; 1:50pm
URL: https://forum.jogamp.org/How-do-I-load-texture-array-in-jogl-tp4039107p4039110.html
Thank you for the advice.
I ve tried to load TextureData, but it's buffer appears empty, so I don't see any image.
Previously I loaded it using File class instance created from image file (commented overload)
Now I load it this way:
public static TextureData loadTextureData (String filePath, GL4 gl) throws GLException, IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(ImageIO.read(new File(filePath)), "png", outputStream);
InputStream fileInputStream = new ByteArrayInputStream(outputStream.toByteArray());
return TextureIO.newTextureData(gl.getGLProfile(), fileInputStream, false, null);
//return TextureIO.newTextureData(gl.getGLProfile(), imageFile, false, null);
}
-----Loading data to texture array------
IntBuffer texture = IntBuffer.allocate(1);
gl.glGenTextures(1, texture);
gl.glActiveTexture(GL4.GL_TEXTURE0);
gl.glBindTexture(GL4.GL_TEXTURE_2D_ARRAY, texture.get(0));
System.out.println("loadTextureArray func 0:" + gl.glGetError());
gl.glTexStorage3D(GL4.GL_TEXTURE_2D_ARRAY, 1, GL4.GL_RGBA8, texLayerWidth, texLayerHeight, textures.size());
System.out.println("loadTextureArray func 1:" + gl.glGetError());
int arraySpot = 0;
for (TextureData texData: textures) {
gl.glTexSubImage3D(GL4.GL_TEXTURE_2D_ARRAY, 0, 0, 0, arraySpot++, texLayerWidth, texLayerHeight,
1, GL4.GL_RGBA, GL4.GL_BYTE, texData.getBuffer());
}
texData.getBuffer().toString() is "java.nio.DirectByteBuffer[pos=0 lim=819200 cap=819200]"