Main Menu

EXTAbgr

Started by WiESi, April 16, 2005, 11:06:21

Previous topic - Next topic

WiESi

Hi!

As OpenGL is not capable of ARGB I thought using java.awt.image.BufferedImage with type TYPE_4BYTE_ABGR would be the easiest way because I then can use the OpenGL-extension EXTAbgr. Although the extension is available on my PC the colors are wrong. What's wrong with this?

BufferedImage t = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
// Drawing on the BufferedImage...
// ...
int[] data = new int[t.getWidth() * t.getHeight() * 4];
t.getRaster().getPixels(0, 0, t.getWidth(), t.getHeight(), data);
ByteBuffer dat = ByteBuffer.allocateDirect(data.length);
dat.order(ByteOrder.nativeOrder());
for(int i = 0; i < data.length; i++) {
	dat.put((byte)data[i]);
}
dat.flip();
// Creating and binding texture...
// ...
GL11.glTexImage2D(target, 0, GL11.GL_RGBA, width, height, 0, EXTAbgr.GL_ABGR_EXT, GL11.GL_UNSIGNED_BYTE, dat);


WiESi

Zero

I once found writing a png loader that there was argb abgr bgra rgba so you migh tjust have the channels mixed up, for instance you think  you are loading rgba but you are really loading bgra (only the b and r are swapped in this example so the alpha and green are correct and it looks weird).   I was loading into ints though and &'ing and shifting the bits i needed into bytes though.  But still that is what it is doing behind the scenes.

Hope that helps.