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~~