So, I am using this code from a JOGL piece from NeHe’s site to load a 32 bit .PNG file with alpha:
public static void makeRGBTexture(GL gl, GLU glu, [i]BufferedImage img[/i], int target, boolean mipmapped)
{
ByteBuffer dest = null;
switch (img.getType())
{
case BufferedImage.TYPE_3BYTE_BGR:
case BufferedImage.TYPE_4BYTE_ABGR:
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(img.getType() == BufferedImage.TYPE_4BYTE_ABGR)
{
if (mipmapped)
{
glu.gluBuild2DMipmaps(target, GL.GL_RGBA, img.getWidth(), img.getHeight(), GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, dest);
}
else
{
gl.glTexImage2D(target, 0, GL.GL_RGBA, img.getWidth(), img.getHeight(), 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, dest);
}
}
else // texture map has no alpha
{
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);
}
}
}
The problem is that a texture mapped surface (with blending enabled) [glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE)] is blended okay, but the colors are completely wrong.
If I set this part
if(img.getType() == BufferedImage.TYPE_4BYTE_ABGR)
to
if( true )
forcing the img.getType() == BufferedImage.TYPE_4BYTE_ABGR code to run, the texture mapped surface looks correct, but other polygons with alpha blending and no texture mapping are invisible. It’s weird. ???
So do you see something wrong with the code, which is not specifically a .PNG loader, but a texture maker with the BufferedImage img full of a .PNG file’s contents?