Binding Texture exception~~

hi~
I now want to map a texture on the object with following code:

[b] private BufferedImage readPNGImage(String resourceName) {
try {
BufferedImage img = ImageIO.read(getClass().getClassLoader().getResourceAsStream(resourceName));
if (img == null) {
throw new RuntimeException("Error reading resource " + resourceName);
}
return img;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void makeRGBTexture(GL gl, GLU glu, BufferedImage img, int target, boolean mipmapped) {
ByteBuffer dest = null;
switch (img.getType()) {
case BufferedImage.TYPE_3BYTE_BGR:
case BufferedImage.TYPE_CUSTOM: {
byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
dest = ByteBuffer.allocateDirect(data.length);
dest.order(ByteOrder.nativeOrder());
dest.put(data, 0, data.length);
break;
}

case BufferedImage.TYPE_INT_RGB: {
  int[] data = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
  dest = ByteBuffer.allocateDirect(data.length * BufferUtils.SIZEOF_INT);
  dest.order(ByteOrder.nativeOrder());
  dest.asIntBuffer().put(data, 0, data.length);
  break;
}

default:
  throw new RuntimeException("Unsupported image type " + img.getType());
}

if (mipmapped) {
  glu.gluBuild2DMipmaps(target, GL.GL_RGB8, img.getWidth(), img.getHeight(), GL.GL_RGB,
                        GL.GL_UNSIGNED_BYTE, dest);
} else {
  gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0,
                  GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
}

}[/b]
but throw following exception ???

[b]java.lang.RuntimeException: Unsupported image type 13

  at jogltest.Main.makeRGBTexture(Main.java:223)

  at jogltest.Main.init(Main.java:50)

  at net.java.games.jogl.impl.GLDrawableHelper.init(GLDrawableHelper.java:68)

  at net.java.games.jogl.GLCanvas$InitAction.run(GLCanvas.java:187)

  at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(WindowsGLContext.java:144)

  at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:110)

  at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:162)

  at net.java.games.jogl.GLCanvas.reshape(GLCanvas.java:105)

  at java.awt.Component.setBounds(Component.java:1664)

  at java.awt.BorderLayout.layoutContainer(BorderLayout.java:691)

  at java.awt.Container.layout(Container.java:1020)

  at java.awt.Container.doLayout(Container.java:1010)

  at java.awt.Container.validateTree(Container.java:1092)

  at java.awt.Container.validateTree(Container.java:1099)

  at java.awt.Container.validateTree(Container.java:1099)

  at java.awt.Container.validateTree(Container.java:1099)

  at java.awt.Container.validate(Container.java:1067)

  at java.awt.Window.show(Window.java:461)

  at jogltest.Applet1.jbInit(Applet1.java:41)

  at jogltest.Applet1.init(Applet1.java:31)

  at com.borland.jbuilder.runtime.applet.AppletTestbed.startApplet(Unknown Source)

  at com.borland.jbuilder.runtime.applet.AppletTestbed.main(Unknown Source)[/b]

Can someone help me to slve this problem…thank~~

Sorry for not coming up with any solution~

I encountered exactly the same problem when applying certain .png images, when others work fine. I need to load an image with transparent background, however, if I make a png image with transparent background I encounter this problem too.

What is the solution to this problem, and is there an easier way to make transparent backgrounds?

Thanks for your time,

Emil Olofsson

Please upgrade to the latest JOGL nightly build on the JOGL home page and try the new TextureIO classes in com.sun.opengl.util.texture. They should be able to handle this with just a couple of lines of code, alpha channels included.

The problem is that the code don’t support all the BufferedImage types. I think it would be a good idee to use BufferedImage.getRGB() in the default case, and treat the image as if it has a alpha channel.

We came up with a solution to this problem today. However, when we tried to apply a transparent background, the whole image turned up more or less transparent. We’d like to make certain colors transparent, such as 0.0f, 0.0f, 0.0f = 100% alpha, and the rest is normal.