Re: Texture Problem (probably gl.glTexImage2D)
Posted by
PedDavid on
Jun 02, 2015; 2:58pm
URL: https://forum.jogamp.org/Texture-Problem-probably-gl-glTexImage2D-tp4034564p4034584.html
Well, got a test working with this code:
textures = new int[1];
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);
try {
BufferedImage image = ImageIO.read(getClass().getClassLoader().getResource("resource/crate.png"));
DataBufferByte dbb = (DataBufferByte)image.getRaster().getDataBuffer();
byte[] data = dbb.getData();
ByteBuffer pixels = BufferUtil.newByteBuffer(data.length);
pixels.put(data);
pixels.flip();
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, 256, 256, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, pixels);
} catch(Throwable t) {
t.printStackTrace();
}
source:
http://www.java-gaming.org/index.php?topic=20725.0But it is rendering with blue/red swapped (calling GL.GL_BGR gets the "true color"). When looking on the internet it seems that usually that happens with bmp instead of png though
Thanks for the tips and I will take a look at the book