LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Vifani83 on March 14, 2005, 16:50:46

Title: DevIL invert the textures
Post by: Vifani83 on March 14, 2005, 16:50:46
Hi guys,

I am some trouble with DevIL library. When I load a texture with the following code I have an invert texture on X axis.

This is the code I use to load:


IL.create();
IL.ilInit();
IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(1, image);
IL.ilBindImage(image.get(0));
IL.ilLoadImage(JConfig.imageDir+fileName);
IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);
format=GL11.GL_RGB;
data = IL.ilGetData();
height=IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
width=IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D,0,texTool.getFormat(),texTool.getWidth(),texTool.getHeight(),0,texTool.getFormat(),GL11.GL_UNSIGNED_BYTE,texTool.getData());


If I look the code to load a texture  using AWT I have seen the following instructions:

AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -tmpImg.getHeight(null));
final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
tmpImg = op.filter(tmpImg, null);


So, why I need to flip the image also with DevIL library? I have read the Chman tutorial and he doesn't flip the texture with DevIL library.
Title: DevIL invert the textures
Post by: tomb on March 14, 2005, 17:35:01
The opengl coordinate system is up side down. You can fix that with the following code. It makes (0, 0) be the upper left corner instead of lower left. Then you don't have to flip your textures. I think :?:

// setup ortho mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, width, height, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
Title: Re: DevIL invert the textures
Post by: CaptainJester on March 14, 2005, 17:53:35
Quote from: "Vifani83"Hi guys,

I am some trouble with DevIL library. When I load a texture with the following code I have an invert texture on X axis.

This is the code I use to load:


If I look the code to load a texture  using AWT I have seen the following instructions:

So, why I need to flip the image also with DevIL library? I have read the Chman tutorial and he doesn't flip the texture with DevIL library.
It depends on the image type you are using.  Some images store the image backwards, some store it forwards.  DevIL just gets the data, it does not convert it for you automatically.

I haven't spent time yet to try and figure out an easy way to flip it with DevIL, so I don't know how.  I just make sure I use and image type that store the image data in a forward order.  PNG does this.
Title: DevIL invert the textures
Post by: jam007 on March 14, 2005, 18:44:50
I use ILU in 0.95

Quote
if (!IL.ilLoadImage(filename)) {
          System.out.println("File not found "+filename);
          throw new TextureNotFoundException(filename);
}
ILU.iluFlipImage();

BUT
I have problems with some image formats.
.jpg works perfectly
.gif  crashes the VM with an ati-driver error
.png and .tif turns into some strange striped version of the original.

Anders